1. 程式人生 > >Autofac使用代碼方式進行組件註冊【不需要依賴】

Autofac使用代碼方式進行組件註冊【不需要依賴】

uil cnblogs crop com ont factory www auto med

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

Autofac使用代碼方式進行組件註冊【不需要依賴】