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


C# ContainerBuilder.RegisterWebApiModelBinders方法代码示例

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


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

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

示例2: Configuration

        public void Configuration(IAppBuilder app)
        {
            var autoFacBuilder = new ContainerBuilder();
            HttpConfiguration config = new HttpConfiguration();

            ConfigureAutoFac(autoFacBuilder);
            autoFacBuilder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            autoFacBuilder.RegisterWebApiFilterProvider(config);
            autoFacBuilder.RegisterWebApiModelBinders(Assembly.GetExecutingAssembly());
            var container = autoFacBuilder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
            ConfigureAuth(app);
            WebApiConfig.Register(config);


            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            app.UseWebApi(config);

            config.EnsureInitialized();

        }
开发者ID:nandithakw,项目名称:hasl,代码行数:25,代码来源:Startup.cs

示例3: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.Register(x => new HttpContextWrapper(HttpContext.Current))
                   .InstancePerApiRequest()
                   .As<HttpContextBase>();

            builder.RegisterApiControllers(ThisAssembly);
            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
            builder.RegisterWebApiModelBinderProvider();
            builder.RegisterWebApiModelBinders(ThisAssembly);
        }
开发者ID:patrickwensel,项目名称:WS,代码行数:11,代码来源:WebApiModule.cs

示例4: SetDependencyResolver

        private void SetDependencyResolver()
        {
            var builder = new ContainerBuilder();

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

            builder.RegisterWebApiModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            builder
                .RegisterAssemblyTypes(
                    Assembly.GetExecutingAssembly(),
                    Assembly.GetAssembly(typeof(DataService)),
                    Assembly.GetAssembly(typeof(WebApiDataService)),
                    Assembly.GetAssembly(typeof(OpdsDataService)),
                    Assembly.GetAssembly(typeof(ConvertService)),
                    Assembly.GetAssembly(typeof(SocialService)),
                    Assembly.GetAssembly(typeof(MailService)),
                    Assembly.GetAssembly(typeof(OAuth2Client)),
                    Assembly.GetAssembly(typeof(RestClient)),
                    Assembly.GetAssembly(typeof(SocialIdentityInjector))
                ).AsImplementedInterfaces().AsSelf();

            builder.RegisterType<SearchService>()
                    .AsImplementedInterfaces()
                    .OnActivating(e => e.Instance.Initialize(new SearchStorageModel
                    {
                        DirectoryName = HttpRuntime.AppDomainAppPath,
                        StorageType = SearchStorageTypeEnum.FileSystem
                    }));

            builder.RegisterType<AuthorizationRoot>()
                   .WithParameter(new NamedParameter("sectionName", "oauth2"));

            builder.RegisterType<SocialIdentityInjector>().PropertiesAutowired();

            builder.RegisterFilterProvider();

            IContainer container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
开发者ID:avgx,项目名称:knigoskop,代码行数:44,代码来源:Global.asax.cs

示例5: RegisterDependencies

        public void RegisterDependencies(ContainerBuilder containerBuilder, Assembly[] assemblies)
        {
            containerBuilder.RegisterAutofacModule(new AutofacWebTypesModule());

            // Mvc:
            containerBuilder.RegisterControllers(assemblies);
            containerBuilder.RegisterFilterProvider();
            containerBuilder.RegisterModelBinderProvider();
            containerBuilder.RegisterModelBinders(assemblies);

            // Web Api:
            containerBuilder.RegisterApiControllers(assemblies);
            containerBuilder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
            containerBuilder.RegisterWebApiModelBinderProvider();
            containerBuilder.RegisterWebApiModelBinders(assemblies);

            // Default auto registrations
            containerBuilder.RegisterAssemblyTypes(assemblies).Where(t => t.IsAssignableTo<IRouteRegistrar>()).As<IRouteRegistrar>().SingleInstance();
            containerBuilder.RegisterAssemblyTypes(assemblies).Where(t => t.IsAssignableTo<IBootTask>()).As<IBootTask>().SingleInstance();
            containerBuilder.RegisterAssemblyTypes(assemblies).Where(t => t.IsAssignableTo<AreaRegistration>()).As<AreaRegistration>().SingleInstance();
        }
开发者ID:BernhardGlueck,项目名称:Phare,代码行数:21,代码来源:WebApplicationModule.cs

示例6: ConfigureDI

        public IContainer ConfigureDI(IAppBuilder app, HttpConfiguration config)
        {
            var builder = new ContainerBuilder();

            //Repositories
            builder.RegisterType<ApplicationDbContext>().As<ApplicationDbContext>().InstancePerRequest();
            builder.RegisterType<ApplicationUserManager>().As<UserManager<ApplicationUser>>().InstancePerRequest();
            builder.RegisterType<ApplicationRepository<UploadingProgress>>().As<IRepository<UploadingProgress>>().InstancePerRequest();
            builder.RegisterType<ApplicationRepository<SearchQuery>>().As<IRepository<SearchQuery>>().InstancePerRequest();
            builder.RegisterType<CSVImport>().As<IFileImport>().InstancePerRequest();

            builder.RegisterType<ApplicationRepository<Person>>().As<IRepository<Person>>().InstancePerRequest();
            builder.RegisterType<ApplicationRepository<PersonFact>>().As<IRepository<PersonFact>>().InstancePerRequest();
            builder.RegisterType<ApplicationRepository<PersonParameter>>().As<IRepository<PersonParameter>>().InstancePerRequest();

            builder.RegisterType<ApplicationRepository<Document>>().As<IRepository<Document>>().InstancePerRequest();
            builder.RegisterType<ApplicationRepository<DocumentParameter>>().As<IRepository<DocumentParameter>>().InstancePerRequest();
            builder.RegisterType<ApplicationRepository<DocumentFact>>().As<IRepository<DocumentFact>>().InstancePerRequest();

            builder.RegisterType<ApplicationRepository<ParameterName>>().As<IRepository<ParameterName>>().InstancePerRequest();

            builder.RegisterType<ApplicationRepository<Misc>>().As<IRepository<Misc>>().InstancePerRequest();
            builder.RegisterType<ApplicationRepository<MiscName>>().As<IRepository<MiscName>>().InstancePerRequest();

            builder.RegisterType<ReportRepository<DocumentOnControl>>().As<IReportRepository<DocumentOnControl>>().InstancePerRequest();

            ////Authorization
            builder.RegisterType<ApplicationOAuthProvider>().As<IOAuthAuthorizationServerProvider>();
            builder.RegisterType<QueryStringOAuthBearerProvider>().As<IOAuthBearerAuthenticationProvider>();

            // Register your Web API controllers.
            builder.RegisterWebApiFilterProvider(config);
            builder.RegisterWebApiModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            return container;
        }
开发者ID:o-panikarovskiy,项目名称:fms,代码行数:40,代码来源:Startup.DI.cs

示例7: Configure

        internal static void Configure(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterInstance(HeroRepository.Current).ExternallyOwned();
            builder.RegisterType<CryptographyService>().As<ICryptographyService>();
            
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiModelBinders(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiModelBinderProvider();

            builder.RegisterType<HeroPropertiesModelBinder>().AsModelBinderForTypes(typeof(HeroPropertiesModel));
            builder.RegisterType<FreeToPlayPeriodPropertiesModelBinder>().AsModelBinderForTypes(typeof(FreeToPlayPeriodPropertiesModel));

            config.ParameterBindingRules.Add(typeof(HeroPropertiesModel), p => p.BindWithModelBinding());
            config.ParameterBindingRules.Add(typeof(FreeToPlayPeriodPropertiesModel), p => p.BindWithModelBinding());

            IContainer container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
开发者ID:sthiakos,项目名称:General,代码行数:23,代码来源:Global.asax.cs

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


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