I’m working on a solution that interacts with Redis, using the servicestack.net library.
I have a class that inherits from ServiceStack.AppHostBase and asks me for an override of the Configure method. This method has as a parameter a Funq.Container that I see is an implementation of IServiceProvider, IResolver and IContainer, and none of these interfaces have the AddHttpClient method that is provided by the IServiceCollection. Method I need to be able to inject the IHttpClientFactory. Any idea how to solve my problem?
2
Answers
This is the interface definition of
IServiceCollection
from IServiceCollection.cs:AddHttpClient
is just an extension method from Microsoft.Extensions.DependencyInjection that wraps adding a number of additional dependencies to ASP.NET Core IOC.So you should continue to register it on ASP.NET Core IOC, i.e:
As any dependencies registered .NET Core Startup are also available to ServiceStack.
To do it in ASP.NET (not .NET Core), the quick way would be to:
Microsoft.Extensions.DependencyInjection
package and call.AppHttpClient()
extensionIHttpClientFactory
from the Service ProviderIHttpClientFactory
withFunq.Container
againIf you happen to use Unity Adaptor
Unity has a package to give you an extension as well to build the Service Provider directly into the Unity Container: