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

Add named and typed clients section #32456

Conversation

peter-csala
Copy link

@peter-csala peter-csala commented Apr 29, 2024

This PR is basically a follow up of my other PR against the dotnet/docs repository.

It extends the Make HTTP requests using IHttpClientFactory in ASP.NET Core page with named and typed client capability.


Internal previews

📄 File 🔗 Preview link
aspnetcore/fundamentals/http-requests.md Make HTTP requests using IHttpClientFactory in ASP.NET Core

@Rick-Anderson
Copy link
Contributor

@IEvangelist I'll do the edit review after you do the technical review.

@Rick-Anderson Rick-Anderson self-assigned this May 23, 2024
@peter-csala
Copy link
Author

@IEvangelist Hi David, can I ask you to please review my PR?

@IEvangelist
Copy link
Member

I had a look, seems ok - but let's please have @CarnaViire review this for technical accuracy instead.

Copy link
Member

@CarnaViire CarnaViire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tagging me @IEvangelist!

While I appreciate your contribution @peter-csala I believe this is not a good guidance, see my comment #32456 (comment). If you strongly believe using multiple named clients should be highlighted in the docs, I'd propose to change the guidance to the one I provided in the comment.

I see that dotnet/docs#40359 was merged but I missed it -- @IEvangelist I think we would need to either revert it or substitute it with the guidance from #32456 (comment).

On a side note:
I also keep thinking that we need to make some effort to reduce duplications between the docs -- as HttpClientFactory belongs to BCL now, it would be better to have the conceptual docs there, and only leave ASP.NET Core related stuff here, and redirect to .NET docs otherwise. But this needs to be done carefully, not to disrupt the users flow. Let's discuss it later @IEvangelist

@peter-csala
Copy link
Author

Thank you @CarnaViire for the review. I agree that my made up example is not the best. I wanted to create a simple example to showcase the usage of named and typed clients because (for some unknown reason) they are not listed on any of the documentation pages. Neither here nor on the dotnet docs.

Do you have any idea what would be an ideal sample scenario for this?

@peter-csala
Copy link
Author

Thank you Natalia for your "constructive" suggestions...

@CarnaViire
Copy link
Member

I agree that my made up example is not the best.

@peter-csala The main problem is not with the example, but with the approach in general.

showcase the usage of named and typed clients because (for some unknown reason) they are not listed on any of the documentation pages

I assume by "the usage of named and typed clients" you mean using several named clients within a service, which you wanted to register and construct via typed clients infrastructure. As I mentioned in my comment, typed clients are simply not designed to be used this way, and ITypedHttpClientFactory interface is not intended to be used in the application code, it is public only for the sake of being able to substitute its implementation e.g. in tests. That's the reason behind it "not being listed" -- simply because we don't consider it being a recommended approach.

You can see the following remarks in the docs:

The ITypedHttpClientFactory is infrastructure that supports the AddHttpClient(IServiceCollection, String) and AddTypedClient(IHttpClientBuilder) functionality. This type should rarely be used directly in application code, use GetService(Type) instead to retrieve typed clients.

So, if your wish is to use several named clients within a service, I've given you several ways to do that; if for some reason neither of them suit your needs, or there are other problems you are trying to solve, please let me know. If there's a real-world scenario which is impossible or significantly complicated with the existing API shape, we'd love to know that.

You can also check some of the issues (in dotnet/runtime) that are already known to us, e.g. this one dotnet/runtime#89755 could further simplify the use of multiple named clients. Please upvote if there's something you need, to help us prioritize. Thanks!

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.

None yet

4 participants