Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving DI configuration #204

Merged
merged 12 commits into from
Jun 21, 2022
Merged

Improving DI configuration #204

merged 12 commits into from
Jun 21, 2022

Conversation

Turnerj
Copy link
Member

@Turnerj Turnerj commented Jun 16, 2022

I always thought the DI story was a little janky, requiring you to specify arrays for the layers and extensions. Plus when it comes to configuring any layers, it makes a bit of a mess.

This PR changes that and makes a more fluent API around building a cache stack. Here is the general plan:

Before

services.AddCacheStack<MyContext>(
    new ICacheLayer[] { new MemoryCacheLayer() }, 
    new ICacheExtension[] { new AutoCleanupExtension(TimeSpan.FromSeconds(30)) }
);

After

services.AddCacheStack<MyContext>(builder => builder
    .AddMemoryCacheLayer()
    .WithCleanupFrequency(TimeSpan.FromSeconds(30))
);

The result of these changes should make adding cache layers and extensions easier/more discoverable. Additionally, configuring the cache layers and extensions becomes a bit cleaner.

@Turnerj Turnerj added the enhancement New feature or request label Jun 16, 2022
Turnerj added 11 commits June 19, 2022 14:39
One key piece that has changed with this is that RedisLockOptions is now a record struct and rather than spin time (et al) on the options directly, that now sits on a "LockCheckStrategy" instead. This is a breaking change for configuring Redis lock options.
This drops the explicit cache layer specification on the extension to instead do a lookup of local cache layers against the CacheStack.
This now uses a similar "options" pattern like the other cache layers
This does mean users _can_ interface with cache layers directly however it is intentionally done on a separate interface.
@Turnerj Turnerj merged commit 238ce72 into main Jun 21, 2022
@Turnerj Turnerj deleted the improving-dependencyinjection branch June 21, 2022 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant