public class AutofacFactory2 { IBank bank; public AutofacFactory2() { Type objTypeService = Type.GetType("Cropay.Bank.IBank"); Type objTypeA = Type.GetType("Cropay.Bank.Bank50"); Type objTypeB = Type.GetType("Cropay.Bank.Bank51"); var builder = new ContainerBuilder(); builder.RegisterType(objTypeA).Named("Cropay.Bank.Bank50", objTypeService); builder.RegisterType(objTypeB).Named("Cropay.Bank.Bank51", objTypeService); IContainer container = builder.Build(); bank = container.ResolveNamed<IBank>("Cropay.Bank.Bank51"); }
https://www.cnblogs.com/kissfu/p/3482069.html#t1
转载于:https://www.cnblogs.com/tsql/p/10556088.html