Autofac注入-创新互联

创新互联建站是一家专业提供潞城企业网站建设,专注与网站设计制作、成都网站制作、成都h5网站建设、小程序制作等业务。10年已为潞城众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。>  一:
      var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest(); builder.RegisterType().As().InstancePerHttpRequest(); IContainer container= builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes);
      二:       var builder = new ContainerBuilder();        builder.RegisterType().As();        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();base.Load(builder);
        }

文章题目:Autofac注入-创新互联
网站链接:http://bzwzjz.com/article/dogggg.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站建设 成都网站建设公司 成都网站设计 网站制作公司 成都网站设计 成都网站建设 营销网站建设 成都网站建设 成都响应式网站建设公司 成都定制网站建设 LED网站设计方案 手机网站建设套餐 成都网站建设 网站设计制作 营销型网站建设 品牌网站建设 企业网站设计 外贸网站建设 手机网站制作 响应式网站设计 成都网站制作 宜宾网站设计