More and more .NET Core libraries is bound to IServiceCollection
. In example, I want to use HttpClientFactory
described here in my NET Framework 4.7.1. desktop application. My application is using Unity IoC. I referenced Microsoft.Extensions.Http
as NuGet.
But there is a problem: new ASP.Net Core components are bound to Microsoft DI framework for .NetCore - IServiceCollection
. In example, registration of HttpClientFactory
is here:
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
}
I was going deeper into MS code and wanted to manually register corresponding interfaces and classes to Unity. This is how services are registered by IServiceCollection:
services.TryAddTransient<HttpMessageHandlerBuilder, DefaultHttpMessageHandlerBuilder>();
services.TryAddSingleton<IHttpClientFactory, DefaultHttpClientFactory>();
This would be no problem to move this to Unity IoC, but I am stucked when I want to register DefaultHttpMessageHandlerBuilder
and DefaultHttpClientFactory
which have internal visibility. So they are not available for registration outside of MS code.
Do I have any chance how to resolve this situation?
internal
, so that's that, you can't directly use them. Just wanted to add a thought: can you set up your Unity IOC so that it resolvesIHttpClientFactory
by in turn resolvingIHttpClientFactory
from the ASP.NETIServiceCollection
? – Taliped