autofac

 public class StaffController : Controller

    {



        private ITest _test;
  //构造函数注入
public StaffController(ITest test) { this._test = test; } }
public class LeaveController : Controller

    {
    //属性注入
public ITest Test { get; set; }     
  
    public ActionResult Index() { return View("Index", "", this.Test.Test()); } }
 
   

 

 
  
           
       var builder = new ContainerBuilder(); builder.RegisterModule<AttributedMetadataModule>(); builder.RegisterModule(new ConfigurationSettingsReader());
//被属性注入的类要写
.PropertiesAutowired()
       builder.RegisterControllers(typeof(MvcApplication).Assembly)

                    .PropertiesAutowired().InstancePerHttpRequest();            

            builder.RegisterSource(new ViewRegistrationSource());

           

            var container = builder.Build();



            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

 

还要写一个扫描bin路径下dll

你可能感兴趣的:(auto)