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


C# ContainerBuilder.RegisterModelBinders方法代码示例

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


在下文中一共展示了ContainerBuilder.RegisterModelBinders方法的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: 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

示例3: 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

示例4: Configure

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

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

            builder
                .Register(c => NHibernateConfig.SessionFactory.OpenSession())
                .As<ISession>().InstancePerHttpRequest();

            builder.RegisterType<CsvFileTextService<ForwardTextCandidate>>().As<ITextService<ForwardTextCandidate>>();
            builder.RegisterType<CsvFileTextService<ReplyTextCandidate>>().As<ITextService<ReplyTextCandidate>>();

            builder.RegisterType<Repository<ForwardTextCandidate>>().As<IBaseRepository<ForwardTextCandidate>>();
            builder.RegisterType<Repository<ReplyTextCandidate>>().As<IBaseRepository<ReplyTextCandidate>>();

            builder.Register<ServerStatusService>(c=>new ServerStatusService(NHibernateConfig.SessionFactory));
            builder.RegisterType<UserService>();

            builder.RegisterType<ServerProvidersAdminSettingsController>();
            builder.RegisterType<UsersController>();

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Create the dependency resolver.
            var resolver = new AutofacWebApiDependencyResolver(container);

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

        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:34,代码来源:DependencyInjectionConfig.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: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: RegisterTypes

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

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

            builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterModelBinderProvider();
            builder.RegisterModule<AutofacWebTypesModule>();
            builder.RegisterSource(new ViewRegistrationSource());
            builder.RegisterFilterProvider();

            builder.Register(x => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
            builder.RegisterType<WorkaroundEmailService>().As<IEmailService>().SingleInstance();

            RegisterServices(builder);
            RegisterBackgroundTasks(builder);

            builder.RegisterType<AuctioneerDbContext>().InstancePerRequest();

            builder.RegisterType<BreadcrumbBuilder>().As<IBreadcrumbBuilder>().InstancePerDependency();
            builder.RegisterType<AuthenticationManager>().As<IAuthenticationManager>().InstancePerRequest();
            builder.RegisterType<EmailUserNotifier>().As<IUserNotifier>().SingleInstance();
            builder.RegisterType<LanguageService>().As<ILanguageService>().SingleInstance();
            builder.RegisterType<AuctionService>().As<IAuctionService>().InstancePerRequest().WithParameters(new Parameter[]
            {
                new NamedParameter("photoDirectoryPath",     HostingEnvironment.MapPath("~/Content/UserContent/Auctions/Photos")),
                new NamedParameter("thumbnailDirectoryPath", HostingEnvironment.MapPath("~/Content/UserContent/Auctions/Thumbnails"))
            });

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:Strachu,项目名称:Auctioneer,代码行数:34,代码来源:ContainerConfig.cs

示例15: RegisterDependencies

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

            builder.RegisterType<Config>().As<IConfig>();
            builder.RegisterType<JsonConverter>().As<IConverter>().InstancePerRequest();
            builder.RegisterType<CustomWebClient>().As<IWebClient>().InstancePerRequest();
            builder.RegisterType<GitHubService>().As<IVcsService<GitHubUser, GitHubRepository>>().InstancePerRequest();

            // 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));
        }
开发者ID:sdesyllas,项目名称:github-explorer,代码行数:29,代码来源:AutofacConfig.cs


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