[Feature request]: Make 'PipelineDisposed' event available on ResiliencePipelineProvider
damienhoneyford opened this issue · comments
Is your feature request related to a specific problem? Or an existing feature?
For long-lived services with a reference to an existing ResiliencePipeline
to be able to respond to that pipeline having been disposed due to a configuration change (when EnableReloads
is used) they need a way of knowing that the pipeline has been disposed.
Currently it requires some 'acrobatics' to forward the notification provided by the OnPipelineDisposed
callback on ConfigureBuilderContext<TKey>
or AddResiliencePipelineContext<TKey>
to the consumer of a ResiliencePipeline
so that they can fetch an updated instance of the ResiliencePipeline
they're using.
Describe the solution you'd like
Add an event or callback to ResiliencePipelineProvider
that can be used by a long-lived service to fetch an updated ResiliencePipeline
instance.
public class MyLongLivedService : IDisposable
{
private readonly ResiliencePipelineProvider<string> _provider;
private ResiliencePipeline _pipeline;
public MyLongLivedService(ResiliencePipelineProvider<string> resiliencePipelineProvider)
{
_provider = resiliencePipelineProvider;
_provider.PipelineDisposed += ReloadPipeline;
_pipeline = _provder.GetPipeline("my-pipeline");
}
private void ReloadPipeline()
{
_pipeline = _provder.GetPipeline("my-pipeline");
}
public void Dispose()
{
_pipeline.PipelineDisposed -= ReloadPipeline;
}
}
Additional context
I'm not sure whether Microsoft have moved away from events as most of their newer code seems to favour callbacks from what I've seen.
Hey @damienhoneyford, the MyLongLivedService
is not necessary, because Polly already does the reload transparently automatically.
When you enable the reloads, Polly returns a wrapper pipeline that is aware of reloads and it does something very similar than your example. Additionally, it also disposes the old pipeline.
Effectively those means that you can retrieve the pipeline once and keep it for that rest of application lifetime even when reloads are enabled.