Comments (4)
This seems reasonable to me - what do you think @martintmk?
from polly.
I think the proposal addresses reasonable feature-gap. The only downside is ambiguity of ConfigureResiliencePipelineRegistry
method that suggests (by the name) that ResiliencePipelineRegistryOptions<TKey>
should be accepted. Instead, what it really does is to populate already configured registry with a new resilience pipelines.
How about this?
public static IServiceCollection AddResiliencePipelineRegistry<TKey>(
this IServiceCollection services,
Action<ResiliencePipelineRegistryOptions<TKey>> configure,
Action<InitializeResiliencePipelineRegistryContext<TKey>> initialize)
where TKey : notnull
{
}
public class InitializeResiliencePipelineRegistryContext<TKey>(ResiliencePipelineRegistry<TKey> registry, IServiceProvider serviceProvider)
where TKey : notnull
{
public ResiliencePipelineRegistry<TKey> Registry => registry;
public IServiceProvider ServiceProvider => serviceProvider;
}
Here, we are just adding a new overload for AddResiliencePipelineRegistry
that also allows initializing the registry (for advanced scenarios). It can be called as many times as needed and allows populating the registry.
services.AddResiliencePipelineRegistry<string>(_ => { }, context =>
{
context.Registry.TryAddBuilder("my-pipeline-1", (builder, _) => builder.AddTimeout(TimeSpan.FromSeconds(1)));
context.Registry.TryAddBuilder("my-pipeline-2", (builder, _) => builder.AddTimeout(TimeSpan.FromSeconds(1)));
context.Registry.TryAddBuilder("my-pipeline-3", (builder, _) => builder.AddTimeout(TimeSpan.FromSeconds(1)));
});
services.AddResiliencePipelineRegistry<string>(_ => { }, context =>
{
context.Registry.TryAddBuilder("my-pipeline-4", (builder, _) => builder.AddTimeout(TimeSpan.FromSeconds(1)));
context.Registry.TryAddBuilder("my-pipeline-5", (builder, _) => builder.AddTimeout(TimeSpan.FromSeconds(1)));
context.Registry.TryAddBuilder("my-pipeline-6", (builder, _) => builder.AddTimeout(TimeSpan.FromSeconds(1)));
});
(first callback configures the options, but we don't want to modify those, so I just provided empty lambda).
Wdyt, could this work for you?
from polly.
I agree that the naming of ConfigureResiliencePipelineRegistry
does leave some ambiguity, and given that the implementation (at least the intial one I hurried together) contains very similar code to the AddResiliencePipeline
methods, it likely would be better named something akin to those. I did initially consider naming the method AddResiliencePipelines
but felt like it was more in-keeping with other libraries to use 'Configure...'.
The big drawback for me in your proposed implementation, @martintmk, is that it works directly with the ResiliencePipelineRegistry
class, which means it misses out on all the goodness available in the AddResiliencePipelineContext
class -- possibly which could be introduced via a method on your proposed InitializeResiliencePipelineRegistryContext
class though.
from polly.
I like the AddResiliencePipelines<TKey>
, since it's something that it actually does. It's pretty unambiguous.
It can accept callback that has access to AddResiliencePipelinesContext<TKey>
on which there are the following methods:
void AddResiliencePipeline(
TKey key,
Action<ResiliencePipelineBuilder, AddResiliencePipelineContext<TKey>> configure);
void AddResiliencePipeline<TResult>(
TKey key,
Action<ResiliencePipelineBuilder<TResult>, AddResiliencePipelineContext<TKey>> configure);
Should support your and more-advanced scenarios pretty well.
from polly.
Related Issues (20)
- [Question]: Customize telemetry event severity? HOT 10
- [Bug]: Retry Startegy stops retrying unexpectedly
- [Feature request]: Make 'PipelineDisposed' event available on ResiliencePipelineProvider HOT 1
- [Question]: Polly 8.2.0 Why Timeout not effective? HOT 9
- [Question]: Replacing ResiliencePipelineProvider with keyed services HOT 8
- [Bug]: ResiliencePipelineBuilder AddCircuitBreaker grows stacktrace uncontrollably HOT 11
- [Feature request]: Relax validation of TimeoutStrategyOptions.Timeout HOT 4
- how to use it for retry but not fault situation? HOT 10
- [Question]: Circuit Breaker: Using BreakDurationGenerator to implement exponential backoff of open to half-open state HOT 1
- [Question]: Polly v8.2.0 how to use AddRetry and AddFallback methods HOT 16
- Simmy API Review and Feedback HOT 32
- [Feature request]: Adding Polly.Telemetry event for being out of retries HOT 4
- [Question]: Is Polly compatible with Unity ? HOT 2
- [Question]: HOT 1
- [Question]: Complex Pipeline Keys documentation example not working as expected HOT 2
- [Question]: Migration from HOT 4
- [Bug]: Retry doesn't happen with FakeTimerProvider.Advance HOT 5
- [Feature request]: Integrate / add support for Lunar Proxy (backend resilience strategy) HOT 3
- [Question]: How can I suppress Execution Attempt log when using Polly V8 ResiliencePipelineBuilder? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polly.