当前位置: 首页>>代码示例>>C#>>正文


C# ContainerBuilder.RegisterModelBinderProvider方法代码示例

本文整理汇总了C#中Autofac.ContainerBuilder.RegisterModelBinderProvider方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterModelBinderProvider方法的具体用法?C# ContainerBuilder.RegisterModelBinderProvider怎么用?C# ContainerBuilder.RegisterModelBinderProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Autofac.ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder.RegisterModelBinderProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterAutofac

        public static void RegisterAutofac()
        {
            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            // If AutofacConfig's assembly doesn't reference the specific controllers assemblies, use these:
            // builder.RegisterControllers(typeof(MvcApplication).Assembly);
            // builder.RegisterControllers(typeof(BasePublicController).Assembly);
            // builder.RegisterControllers(typeof(BaseAdminController).Assembly);
            // ...
            builder.RegisterControllers(BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray());

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Register services
            RegisterServices(builder);

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Integration with Hangfire
            GlobalConfiguration.Configuration.UseAutofacActivator(container);
        }
开发者ID:mpenchev86,项目名称:ASP.NET-MVC-FinalProject,代码行数:35,代码来源:AutofacConfig.cs

示例2: BuildMvcContainer

        /// <summary>
        /// 创建 MVC容器(包含Filter)
        /// </summary>
        public static void BuildMvcContainer()
        {
            var builder = new ContainerBuilder();
            //注册Module方法2 在Web.config中配制方式
            builder.RegisterModule(new ConfigurationSettingsReader("autofacMvc"));
            //加载 *.Controllers 层的控制器,否则无法在其他层控制器构造注入,只能在web层注入
            Assembly[] asm = GetAllAssembly("*.Controllers.dll").ToArray();
            builder.RegisterAssemblyTypes(asm);
            //注册仓储
            Assembly[] asmRepository = GetAllAssembly("*.Repository.dll").ToArray();
            builder.RegisterAssemblyTypes(asmRepository)
               .Where(t => t.Name.EndsWith("Repository"))
               .AsImplementedInterfaces();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();


            //注册过滤器 
            builder.RegisterFilterProvider();
            builder.RegisterType<OperateAttribute>().PropertiesAutowired();//非global filter  属性注入
            builder.RegisterType<GlobalFilterAttribute>().SingleInstance();//global filter 注入
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:ciker,项目名称:201509LoginDemo,代码行数:32,代码来源:AutofacRegistion.cs

示例3: Load

 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterModelBinders(_mvcModule);
     builder.RegisterModelBinderProvider();
     builder.RegisterControllers(_mvcModule);
     builder.RegisterModule(new AutofacWebTypesModule());
 }
开发者ID:nucleoid,项目名称:Wallboard,代码行数:7,代码来源:MvcModule.cs

示例4: CreateContainer

        private void CreateContainer(HttpConfiguration configuration,IApplicationHost applicationHost,IConfigurationProvider configurationProvider)
        {
            var assemblies          = applicationHost.Assemblies.ToArray();
            var containerBuilder    = new ContainerBuilder();

            containerBuilder.RegisterModelBinderProvider();
            //containerBuilder.RegisterFilterProvider(); TODO: Seems to be an autofac MVC4 integration issue
            containerBuilder.RegisterModelBinders(assemblies);
            containerBuilder.RegisterApiControllers(assemblies);
            containerBuilder.RegisterControllers(assemblies);
            containerBuilder.RegisterWebApiFilterProvider(configuration);
            containerBuilder.RegisterWebApiModelBinders(assemblies);
            containerBuilder.RegisterModule(new AutofacWebTypesModule());

            containerBuilder.RegisterAssemblyModules(assemblies);
            containerBuilder.RegisterAssemblyTypes(assemblies).Where(t => t.IsAssignableTo<IRouteProvider>()).As<IRouteProvider>();
            containerBuilder.RegisterAssemblyTypes(assemblies).Where(t => t.IsAssignableTo<IBootTask>()).As<IBootTask>();
            containerBuilder.RegisterAssemblyTypes(assemblies).Where(t => t.IsAssignableTo<AreaRegistration>()).As<AreaRegistration>();

            containerBuilder.RegisterInstance(applicationHost).As<IApplicationHost>();
            containerBuilder.RegisterInstance(configurationProvider).As<IConfigurationProvider>();

            var container = containerBuilder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            SignalR.GlobalHost.DependencyResolver = new AutofacSignalRDependencyResolver(container);
        }
开发者ID:BernhardGlueck,项目名称:Wmc,代码行数:28,代码来源:Global.asax.cs

示例5: RegisterAutofac

        public static void RegisterAutofac()
        {
            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Register services
            RegisterServices(builder);

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:AndrewMitev,项目名称:Telerik-Academy,代码行数:27,代码来源:AutofacConfig.cs

示例6: BuildContainer

        public static void BuildContainer()
        {
            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Add our own components
            builder.RegisterType<NameResolver>().As<INameResolver>();

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .Where(x=>x.Name.EndsWith("Service"))
                .AsImplementedInterfaces();

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:stimms,项目名称:AutofacDemo,代码行数:31,代码来源:ContainerConfig.cs

示例7: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            var builder = new ContainerBuilder();
            builder.RegisterModelBinderProvider();
            builder.RegisterModule(new AutofacWebTypesModule());
            builder.RegisterSource(new ViewRegistrationSource());
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());

            builder.RegisterType<InMemoryPersonRepository>().As<IPersonRepository>();

            // Use application-scoped variable to mimic in-memory database
            var personDatabase = new List<Person>();
            builder.Register(c => personDatabase).As<List<Person>>();

            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            ModelMetadataProviders.Current = new MetadataProvider();
        }
开发者ID:robdmoore,项目名称:ASP.NET-MVC-Terse-Controller-Testing,代码行数:25,代码来源:Global.asax.cs

示例8: UseAutofacInjection

        public static IAppBuilder UseAutofacInjection(this IAppBuilder app, HttpConfiguration httpConfiguration)
        {
            var currentAssembly = Assembly.GetExecutingAssembly();

            var builder = new ContainerBuilder();

            // Web API
            builder.RegisterApiControllers(currentAssembly);
            builder.RegisterWebApiFilterProvider(httpConfiguration);

            // MVC
            builder.RegisterControllers(currentAssembly).PropertiesAutowired();

            builder.RegisterModelBinders(currentAssembly);
            builder.RegisterModelBinderProvider();

            builder.RegisterModule<AutofacWebTypesModule>();
            //builder.RegisterSource(new ViewRegistrationSource());

            builder.RegisterFilterProvider();

            builder.RegisterAssemblyModules(currentAssembly);
            
            // Hook it up
            var container = builder.Build();
            httpConfiguration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Register the Autofac middleware FIRST, then the Autofac MVC middleware.
            app.UseAutofacMiddleware(container);
            app.UseAutofacMvc();

            return app;
        }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:34,代码来源:AutofacConfig.cs

示例9: BuildAutofacContainer

        private static IContainer BuildAutofacContainer(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            //Register Dependencies
            RegisterIdentityParts(app, builder);
            RegisterImageParts(app, builder);
            RegisterContentParts(app, builder);

            return builder.Build();
        }
开发者ID:RodionKulin,项目名称:ContentManagementBackend,代码行数:27,代码来源:AutofacConfig.cs

示例10: ConfigureContainer

        public static IContainer ConfigureContainer()
        {
            var _builder = new ContainerBuilder();

            //Call into our data project and let it register it's common services into the same builder
            TypeScript.Demo.Data.AutofacConfig.RegisterCommonServices(_builder);


            //This code is fairly stock code demonstrating how to tightly integrate Autofac with MVC and WebAPI
            _builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            _builder.RegisterModelBinders(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            _builder.RegisterModelBinderProvider();
            _builder.RegisterModule(new AutofacWebTypesModule());
            _builder.RegisterSource(new ViewRegistrationSource());
            _builder.RegisterFilterProvider();
            _builder.RegisterWebApiModelBinders(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            _builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();

            var _container = _builder.Build();

            // Tell ASP.NET MVC to use Autofac to resolve components
            DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));

            // Create the depenedency resolver for web API
            var resolver = new AutofacWebApiDependencyResolver(_container);

            // Configure Web API with the dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver = resolver;

            return _container;
        }
开发者ID:ArchitectNow,项目名称:TypeScript.Demo,代码行数:31,代码来源:AutofacConfig.cs

示例11: Setup

        public static void Setup()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            // Register for API Controllers
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterFilterProvider();
            builder.RegisterModelBinderProvider();
            builder.RegisterModule<AutofacWebTypesModule>();

            // Find all autofac modules and include them.
            builder.RegisterModule<IdentityModule>();

            // Find all IStartable tasks and register them.
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
            builder.RegisterAssemblyTypes(assemblies)
                .AssignableTo<IStartable>()
                .As<IStartable>()
                .SingleInstance();

            // Enable property injection into action filters (including authorize attribute).
            builder.RegisterFilterProvider();

            IContainer container = builder.Build();
            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:vietplayfuri,项目名称:Asp_Master,代码行数:29,代码来源:DependancyInjectionConfig.cs

示例12: Config

        public static void Config()
        {
            var builder = new ContainerBuilder();

            // Register MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterApiControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            var container = Bootstrap.ServiceLocator.Instance.InitializeIOC(builder);

            // Set the dependency resolver to be Autofac.
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
开发者ID:pray1997,项目名称:SwiftBookingTest,代码行数:27,代码来源:AutofacConfig.cs

示例13: RegisterServices

        protected void RegisterServices()
        {
            var tenantIdStrategy = new RouteDataItemTenantIdentificationStrategy("tenant");

            var builder = new ContainerBuilder();

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Create the multitenant container and the tenant overrides.
            var mtc = new MultitenantContainer(tenantIdStrategy, builder.Build());
            AddTenant(mtc, "a");
            AddTenant(mtc, "b");

            DependencyResolver.SetResolver(new AutofacDependencyResolver(mtc));
        }
开发者ID:mppa-git,项目名称:aspnet4-multitenant-framework,代码行数:29,代码来源:Global.asax.cs

示例14: RegisterBindings

        public static void RegisterBindings()
        {
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            builder.RegisterModule(new Vintage.Rabbit.CQRS.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Carts.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Common.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Products.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Caching.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Messaging.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Orders.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Membership.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Inventory.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Blogs.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Themes.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Search.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Logging.Ioc.Bindings());
            builder.RegisterModule(new Vintage.Rabbit.Parties.Ioc.Bindings());

            builder.RegisterType<LoginProvider>().As<ILoginProvider>();

            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            builder.RegisterFilterProvider();

            builder.RegisterType<HandleExceptionAttribute>().AsExceptionFilterFor<Controller>().InstancePerRequest().PropertiesAutowired();

            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:Brontsy,项目名称:Vintage-Rabbit,代码行数:33,代码来源:AutofacConfig.cs

示例15: Application_Start

        protected void Application_Start()
        {

            var builder = new ContainerBuilder();

            BuildMappings(builder);

            // Register your MVC controllers.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule<AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ConfigureLogging();
        }
开发者ID:ylashin,项目名称:.net-workshops,代码行数:34,代码来源:Global.asax.cs


注:本文中的Autofac.ContainerBuilder.RegisterModelBinderProvider方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。