Skip to content

Add new Polly DI extension method for HttpClientFactory #3142

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

Closed
wants to merge 3 commits into from
Closed

Add new Polly DI extension method for HttpClientFactory #3142

wants to merge 3 commits into from

Conversation

martincostello
Copy link
Member

This pull request adds the following new overload to the Polly extensions for HttpClientFactory:

public static IServiceCollection AddPolicyRegistry(
    this IServiceCollection services,
    Action<IServiceProvider, IPolicyRegistry<string>> configureRegistry)

The existing two registrations allow a policy registry to be registered and then configured directly, but there isn't an overload that takes a delegate and provides the IServiceProvider to allow the policies to be configured based on other registered services, such as settings loaded from IConfiguration.

I've added a unit test that demonstrates the use case of using another service to configure the policies at the point the policy registry dependency is first resolved.

I've also tidied up a few minor trivial things I found while making the change, which I can split into a separate PR if necessary.

@ghost
Copy link

ghost commented Apr 2, 2020

As per aspnet/Announcements#411, we are currently migrating components from this repository to other repositories (dotnet/runtime, dotnet/aspnetcore). We recommend waiting until that process is complete and opening your PR against the appropriate repository. See the original announcement for a list mapping packages to the new repository.

Fix IDE warnings about non-disposed handlers.
Update the comment's type to match the method's.

Fix indentation.
Add a new overload for AddPolicyRegistry() that allows the
caller to configure the policy registry using other services
that are registered with the service provider, such as config.
@martincostello
Copy link
Member Author

Any update here @Pilchie? As far as I could tell from the docs, the library I've changed isn't up for migration and is staying here.

@Pilchie
Copy link
Member

Pilchie commented Jun 10, 2020

Tagging @karelz for HttpClientFactory.

@martincostello
Copy link
Member Author

@karelz Would you be able to take a look at this PR please? It seems to have fallen into a limbo state with the repo reorganisation.

@karelz
Copy link
Member

karelz commented Jun 28, 2020

Sorry for the delay @martincostello . Sadly, we do not have anyone currently with knowledge of this code base. We should be able to look at it (incl. general code transfer) around mid July once we are sure we can deliver all critical features and bug fixes for 5.0.
Will that work for you?

@martincostello
Copy link
Member Author

No problem - thanks!

@martincostello
Copy link
Member Author

Is this too late for 5.0 now?

@karelz
Copy link
Member

karelz commented Aug 14, 2020

We are still finishing 5.0 this week and a bit next week. Then we will have to ramp up on the code base from scratch, so I don't expect we will be able to make it happen with high confidence in 5.0 :(

@karelz
Copy link
Member

karelz commented Oct 12, 2020

Sorry, we finally got our grip on the code base (thanks @CarnaViire!) and got to this PR.
It seems to be specifically about Polly, which should be still owned by ASP.NET team -- @Pilchie who should take a look at Polly part of HttpClientFactory?

@martincostello sorry for the delay, you have been caught unfortunately in the middle of ownership transition where things are a bit messy :(

@ericstj ericstj requested a review from a team October 13, 2020 17:53
@halter73
Copy link
Member

Original PR that added support for policy registry: aspnet/HttpClientFactory#66

@martincostello Did you copy this pattern from anywhere? To me this seems like it's trying to work around the fact that the IPolicyRegistry isn't configured using the ASP.NET Core's Options pattern. If it was, you'd be able to configure policies based on other registered services using Configure.

I'm thinking maybe we should update AddPolicyRegistry to use the Options pattern instead.

@martincostello
Copy link
Member Author

@halter73 Yeah, I based it on the overloads that the various methods for configuring IHttpClientFactory have.

@halter73
Copy link
Member

@davidfowl @Tratcher What are your thoughts about using the Options pattern here?

@Tratcher
Copy link
Member

Action<IServiceProvider, IPolicyRegistry<string>> does resemble an Options pattern. @halter73 do you have a rough idea of what an Options version of this would look like?

@halter73
Copy link
Member

I haven't fully thought it through, but I figure the IPolicyRegistry​<​string​> could be a property in an option type.

@JunTaoLuo
Copy link

FYI, as part of https://github.com/dotnet/aspnetcore-internal/issues/3707, we are moving this component to https://github.com/dotnet/aspnetcore, please re-open this PR in that repo.

@martincostello
Copy link
Member Author

Opened dotnet/aspnetcore#28283.

@martincostello martincostello deleted the Add-New-Polly-DI-Extension branch December 1, 2020 18:23
@ghost ghost locked as resolved and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants