Answer the question
In order to leave comments, you need to log in
Is type rebinding possible in an ASP.Net Core DI container?
The essence of the problem - there is an interface ITest.
It has an implementation based on the TestClass1 class.
In the ConfigureServices method, the binding is created as follows:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ITest, TestClass1>();
}
Answer the question
In order to leave comments, you need to log in
Set it to type Transient and return the required object instance in the factory method
serviceCollection.AddTransient<ITest>((serviceProvider) =>
{
return (<условие>) ? new TestClass1() : new TestClass2();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question