GithubHelp home page GithubHelp logo

Comments (4)

martincostello avatar martincostello commented on June 9, 2024

This seems reasonable to me - what do you think @martintmk?

from polly.

martintmk avatar martintmk commented on June 9, 2024

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.

damienhoneyford avatar damienhoneyford commented on June 9, 2024

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.

martintmk avatar martintmk commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.