• Autofac实现控制器属性注入和过滤器属性注入


        public class MvcApplication : System.Web.HttpApplication
        {
            protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();
                FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
                RouteConfig.RegisterRoutes(RouteTable.Routes);
                BundleConfig.RegisterBundles(BundleTable.Bundles);
    
                ContainerBuilder builder = new ContainerBuilder();
    
                //实现控制器属性注入的关键--PropertiesAutowired()
                builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
    
                //实现过滤器属性注入的关键
                builder.RegisterFilterProvider();
    
                //注册类库程序集
                builder.RegisterAssemblyTypes(Assembly.Load("Repository")).AsImplementedInterfaces().PropertiesAutowired();
    
                //注册类库程序集
                builder.RegisterAssemblyTypes(Assembly.Load("Services")).AsImplementedInterfaces().PropertiesAutowired();
    
                var container = builder.Build();
    
                DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            }
        }
  • 相关阅读:
    随感
    createDocumentFragment() 创建文档碎片节点
    关于数组的map、reduce、filter
    CSS中的常用属性
    精通CSS version2笔记2.小知识
    精通CSS version2笔记之⒈选择器
    Spring入门_01
    Spring入门
    Java 流程控制
    Java 数据类型
  • 原文地址:https://www.cnblogs.com/superfeeling/p/14652550.html
Copyright © 2020-2023  润新知