使用structuremap,我们可以注册这样的接口:
Scan(x =>
{
x.AssemblyContainingType<Startup>();
x.Assembly("Api");
x.LookForRegistries();
x.AddAllTypesOf<Profile>();
x.WithDefaultConventions();
});
如果我有接口和多个具体实现使用该接口,IService,ServiceA,ServiceB,ServiceC,我该如何使用Microsoft DI,或者我必须写下3次addtransient?
策略模式相同:
public class ServiceStrategy : IServiceStrategy
{
private readonly List<IService> _services;
public ServiceStrategy(List<IService> services)
{
this._services= services;
}
public string GetProcedure(Enum enum, EnumTwo enum2)
{
return this._managers.FirstOrDefault(x => x.Type == enum)
?.GetProcedure(enum2);
}
}
我如何在这里注册策略?
答案 0 :(得分:0)
Microsoft.Extensions.DependencyInjection缺少任何自动注册功能,因此您有3个选项:
AddTransient