MVC+ICO AutoFac 依赖注入框架

前端之家收集整理的这篇文章主要介绍了MVC+ICO AutoFac 依赖注入框架前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

DEMO下载地址: http://download.csdn.net/detail/lhfly/4217929

文档中包括表结创建的sql语句

 public class UserModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {   

           builder.RegisterType<UserManager>().As<IUserManager>().InstancePerLifetimeScope();

           base.Load(builder);
        }
    }


 protected void Application_Start()
        {
             
            var builder = new ContainerBuilder();

            //注册Module方法1
            builder.RegisterModule(new UserModule());

            //注册Module方法2  在Web.config中配制
           // builder.RegisterModule(new ConfigurationSettingsReader("autofac"));

            Assembly[] asm = PluginManager.GetAllAssembly().ToArray();
            builder.RegisterAssemblyTypes(asm);

           

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();
            builder.RegisterFilterProvider();//注册Filter           

            builder.RegisterControllers(typeof(MvcApplication).Assembly);
             
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));



            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }

猜你在找的设计模式相关文章