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

posted on 2013-10-25 11:35  聪明的大熊  阅读(472)  评论(0编辑  收藏  举报