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

[Feature] Add support for keyed services #1881

Merged
merged 4 commits into from
Jan 7, 2024
Merged

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Jan 6, 2024

Pull Request

The issue or feature being addressed

#1874

Details on the issue fix or feature implementation

This PR adds support for keyed services into Polly.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

@martintmk martintmk added this to the v8.3.0 milestone Jan 6, 2024
Copy link

codecov bot commented Jan 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (502094f) 84.62% compared to head (a584fdf) 84.66%.
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1881      +/-   ##
==========================================
+ Coverage   84.62%   84.66%   +0.04%     
==========================================
  Files         309      309              
  Lines        6818     6836      +18     
  Branches     1050     1052       +2     
==========================================
+ Hits         5770     5788      +18     
  Misses        839      839              
  Partials      209      209              
Flag Coverage Δ
linux 84.66% <100.00%> (+0.04%) ⬆️
macos 84.66% <100.00%> (+0.04%) ⬆️
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

docs/advanced/dependency-injection.md Outdated Show resolved Hide resolved
docs/advanced/dependency-injection.md Outdated Show resolved Hide resolved
@martintmk martintmk enabled auto-merge (squash) January 7, 2024 18:27
@martintmk martintmk merged commit 28fba68 into main Jan 7, 2024
13 checks passed
@martintmk martintmk deleted the mtomka/keyed-pipelines branch January 7, 2024 19:01
@pekspro
Copy link

pekspro commented Jan 8, 2024

I just want to say thank you for this. I did not expect this at all :-)

@hayohayo
Copy link

hayohayo commented Feb 7, 2024

I did not investigate further, but when I update Polly.Extensions from 8.2.0 to 8.3.0 I start getting this exception:

System.InvalidOperationException: This service descriptor is keyed. Your service provider may not support keyed services.
   at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ThrowKeyedDescriptor()
   at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.get_ImplementationInstance()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.Populate()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory..ctor(ICollection`1 descriptors)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services)
   ...

I think it might be caused by this PR. I should mention, this application is still using .NET 6. In .NET 8 I don't see this exception.

The way I use the resilience pipeline is something like:

// On launch
services.AddResiliencePipeline<string, SomeResult>("someKey", (builder, context) => { /* ... */ });

// Inject into a singleton
class MySingleton
{
    public MySingleton(ResiliencePipelineProvider<string> resiliencePipelineProvider) { }
}

@CSharpFiasco
Copy link

I did not investigate further, but when I update Polly.Extensions from 8.2.0 to 8.3.0 I start getting this exception:

System.InvalidOperationException: This service descriptor is keyed. Your service provider may not support keyed services.
   at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ThrowKeyedDescriptor()
   at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.get_ImplementationInstance()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.Populate()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory..ctor(ICollection`1 descriptors)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services)
   ...

I think it might be caused by this PR. I should mention, this application is still using .NET 6. In .NET 8 I don't see this exception.

The way I use the resilience pipeline is something like:

// On launch
services.AddResiliencePipeline<string, SomeResult>("someKey", (builder, context) => { /* ... */ });

// Inject into a singleton
class MySingleton
{
    public MySingleton(ResiliencePipelineProvider<string> resiliencePipelineProvider) { }
}

I believe this is related dotnet/runtime#95789

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants