I have the following classes structure:
interface IContractService{}
class Service1 : IContractService{}
class Service2 : IContractService{}
class ContractServiceFactory
{
private readonly IServiceProvider _serviceProvider;
ContractServiceFactory(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
IContractService GetContractService(string standard)
{
// Is it possible to retrieve service by string const???
return _serviceProvider.GetRequiredService<IContractService>(standard);
}
}
In the services collection I would like to add my classes in the following way:
builder.Services.AddScoped<IContractService, ContractService1>("standard1");
builder.Services.AddScoped<IContractService, ContractService2>("standard2");
Is it possible in .net core 2.1?