1

我正在使用 Autofac 使用命名绑定将多个具体类型注册到单个接口:

var builder = new ContainerBuilder();

builder.RegisterType<AlphaProvider>().Named<IProvider>("A");
builder.RegisterType<BetaProvider>().Named<IProvider>("B");

var container = b.Build();

DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); 

现在,我需要按名称(“A”或“B”)引用具体类型,但看不到使用 .NET 的方法DependencyResolver

DependencyResolver.Current.GetServices<IProvider>() //<-- How do I get via name?

有没有办法使用名称来获取绑定DependencyResolver

4

0 回答 0