zoukankan      html  css  js  c++  java
  • Autofac注入

               一:
           var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest(); builder.RegisterType<Web_ExceptionLogManager>().As<IWeb_ExceptionLogManager>().InstancePerHttpRequest(); IContainer container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes);
          二:       
    var builder = new ContainerBuilder();        builder.RegisterType<NewsRepository>().As<INewsRepository>();        builder.RegisterControllers(Assembly.GetExecutingAssembly());        IContainer container = builder.Build();        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

          
     
         
    
    
    三:

    protected
    void Application_Start() { var builder = new ContainerBuilder(); builder.RegisterModule(new FrameworkModule()); builder.RegisterModule(new **Module()); Assembly[] assemblies = ModuleManager.GetAllModuleAssembly().ToArray(); builder.RegisterAssemblyTypes(assemblies); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterModelBinders(Assembly.GetExecutingAssembly()); builder.RegisterModelBinderProvider(); builder.RegisterModule(new ConfigurationSettingsReader("*****")); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); }

    public class **Module : Module
        {
            public static string **Context
            {
                get { return "**Context"; }
            }
    
            protected override void Load(ContainerBuilder builder)
            {
                builder.RegisterType<**Repository>().As<I**Repository>();base.Load(builder);
            }
    
    
    
     
    
    
  • 相关阅读:
    Unity3D游戏制作(四)——Asset Server搭建
    查询开户银行的现代化支付行号
    专业版Unity技巧分享:使用定制资源配置文件
    如何建立一个完整的游戏AI
    实现简易而强大的游戏AI——FSM,有限状态机
    iOS 开发 初级:应用内购买 In-App Purchase
    linux每日命令(14):less命令
    flask上传excel文件,无须存储,直接读取内容
    linux每日命令(13):more命令
    linux每日命令(12):nl命令
  • 原文地址:https://www.cnblogs.com/wzq806341010/p/2883384.html
Copyright © 2011-2022 走看看