How do I implement IHttpClientFactory in .net framework apart from .Net core?

时间秒杀一切 提交于 2020-08-24 10:43:07

问题


In .Net core, we can use IHttpClientFactory to inject and use during runtime. As a developer I no need to worry about the dependency resolution. I need to just specify AddHttpClient() in service collection. Likewise, how can I use IHttpClientFactory in WPF application, .net framework 4.6.1? As there is no Service collection available for WPF application, not getting how to resolve the dependency.


回答1:


You can add the Microsoft.Extensions.Http NuGet package to any .NET Standard 2.0-compliant project. That includes projects that target .NET 4.6.1

All of the Microsoft.Extensions.* packages are .NET Standard 2.0 packages, which means you can use the same Configuration, Dependency Injection, Logging services as .NET Core.

Microsoft.Extensions.Http provides the HttpClientFactory only, not the new optimized HttpClient. This is only available in .NET Core 2.1



来源:https://stackoverflow.com/questions/51474776/how-do-i-implement-ihttpclientfactory-in-net-framework-apart-from-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!