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


C# ContainerBuilder.RegisterWebApiModelBinderProvider方法代码示例

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


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

示例1: BuildRegistrations

        internal static IContainer BuildRegistrations()
        {
            var builder = new ContainerBuilder();

            // Register our custom dependencies
            builder.RegisterModule(new ServicesModule());

            // Register dependencies in webapi controllers
            builder.RegisterApiControllers(typeof(MvcApplication).Assembly);

            // Register dependencies in filter attributes
            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

            // Register autofac's provider for webapi's modelbinders.
            builder.RegisterWebApiModelBinderProvider();

            //Obsolete
            //builder.RegisterWebApiModelBinders(typeof(MvcApplication).Assembly);

            builder.RegisterType<WebApiRequestContextModelBinder>().AsModelBinderForTypes(typeof(RequestContext));

            var container = builder.Build();

            // Set WebApi DI resolver to use our Autofac container
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            return container;
        }
开发者ID:devworker55,项目名称:SourceLab,代码行数:28,代码来源:AutofacWebApiBuilder.cs

示例2: Initialize

        public static IContainer Initialize(ContainerBuilder builder, HttpConfiguration config)
        {
            // Register all controllers
            builder.RegisterApiControllers(typeof(Startup).Assembly);

            // Register Autofac filter provider
            builder.RegisterWebApiFilterProvider(config);

            // Register model binders
            builder.RegisterWebApiModelBinderProvider();

            // Register all Autofac specific IModule implementations
            builder.RegisterAssemblyModules(typeof(Startup).Assembly);
            builder.RegisterAssemblyModules(typeof(AutofacMediator).Assembly);

            builder.RegisterModule(new RequestHandlerModule());
            builder.RegisterModule(new EntityFrameworkModule());
            builder.RegisterModule(new DocumentGeneratorModule());

            // http://www.talksharp.com/configuring-autofac-to-work-with-the-aspnet-identity-framework-in-mvc-5
            builder.RegisterType<IwsIdentityContext>().AsSelf().InstancePerRequest();
            builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
            builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
            builder.RegisterType<ApplicationUserManager>().As<UserManager<ApplicationUser>>().InstancePerRequest();

            return builder.Build();
        }
开发者ID:EnvironmentAgency,项目名称:prsd-iws,代码行数:27,代码来源:AutofacBootstrapper.cs

示例3: RegisterComponents

        public override void RegisterComponents(ContainerBuilder builder)
        {
            base.RegisterComponents(builder);
            
            builder.RegisterInstance(this).As<NuGetApiService>();

            var config = ConfigureWebApi();
            builder.RegisterInstance(config).AsSelf();

            builder
                .RegisterApiControllers(GetControllerAssemblies().ToArray())
                .OnActivated(e =>
                {
                    var nugetController = e.Instance as NuGetApiController;
                    if (nugetController != null)
                    {
                        nugetController.Host = Host;
                        nugetController.Service = this;
                        nugetController.Container = Container;
                    }
                })
                .InstancePerApiRequest();

            builder.RegisterWebApiFilterProvider(config);
            builder.RegisterWebApiModelBinderProvider();
        }
开发者ID:stephenosrajan,项目名称:NuGet.Services.Platform,代码行数:26,代码来源:NuGetApiService.cs

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

示例5: BuildAndSetResolver

 /// <summary>
 /// 构建服务并设置WebApi平台的Resolver
 /// </summary>
 /// <param name="services">服务映射信息集合</param>
 /// <param name="assemblies">要检索的程序集集合</param>
 /// <returns>服务提供者</returns>
 protected override IServiceProvider BuildAndSetResolver(IServiceCollection services, Assembly[] assemblies)
 {
     ContainerBuilder builder = new ContainerBuilder();
     builder.RegisterApiControllers(assemblies).AsSelf().PropertiesAutowired();
     builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
     builder.RegisterWebApiModelBinderProvider();
     builder.Populate(services);
     IContainer container = builder.Build();
     IDependencyResolver resolver = new AutofacWebApiDependencyResolver(container);
     GlobalConfiguration.Configuration.DependencyResolver = resolver;
     return (IServiceProvider)resolver.GetService(typeof(IServiceProvider));
 }
开发者ID:Ray898,项目名称:osharp,代码行数:18,代码来源:WebApiAutofacIocBuilder.cs

示例6: BuildContainer

        private static IContainer BuildContainer(Options options)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var builder = new ContainerBuilder();

            var settings = new SettingsRepository(options.MplayerExecutablePath, options.LibraryPath);

            builder.RegisterInstance<ISettingsRepository>(settings);
            builder.RegisterType<SongRepository>().As<ISongRepository>().SingleInstance();

            builder.RegisterType<SongRunner>().SingleInstance();

            builder.RegisterWebApiModelBinderProvider();

            builder.RegisterApiControllers(assembly);

            return builder.Build();
        }
开发者ID:cryovat,项目名称:karasu,代码行数:18,代码来源:Program.cs

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

示例8: Initialize

        public static IContainer Initialize(ContainerBuilder builder, HttpConfiguration config)
        {
            // Register all controllers
            builder.RegisterApiControllers(typeof(Startup).Assembly);

            // Register Autofac filter provider
            builder.RegisterWebApiFilterProvider(config);

            // Register model binders
            builder.RegisterWebApiModelBinderProvider();

            // Register all Autofac specific IModule implementations
            builder.RegisterAssemblyModules(typeof(Startup).Assembly);
            builder.RegisterAssemblyModules(typeof(AutofacMediator).Assembly);
            builder.RegisterModule(new RequestHandlerModule());
            builder.RegisterModule(new CoreModule());
            builder.RegisterModule(new EntityFrameworkModule());
            builder.RegisterModule(new EmailModule());
            builder.RegisterModule(new XmlValidationModule());
            builder.RegisterModule(new EventDispatcherModule());
            builder.RegisterModule(new XmlModule());
            builder.RegisterModule(new SecurityModule());

            // http://www.talksharp.com/configuring-autofac-to-work-with-the-aspnet-identity-framework-in-mvc-5
            builder.RegisterType<WeeeIdentityContext>().AsSelf().InstancePerRequest();
            builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
            builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
            builder.RegisterType<ApplicationUserManager>().As<UserManager<ApplicationUser>>().InstancePerRequest();

            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Weee.DefaultConnection"].ConnectionString;

            builder.RegisterType<SecurityEventDatabaseAuditor>()
                .WithParameter(new NamedParameter("connectionString", connectionString))
                .As<ISecurityEventAuditor>()
                .InstancePerRequest();

            return builder.Build();
        }
开发者ID:EnvironmentAgency,项目名称:prsd-weee,代码行数:38,代码来源:AutofacBootstrapper.cs

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

示例10: RegisterModelBinders

 private static void RegisterModelBinders(ContainerBuilder builder)
 {
     builder.RegisterWebApiModelBinderProvider();
     builder.RegisterType<ObjectIdModelBinder>().AsModelBinderForTypes(typeof(ObjectId));
 }
开发者ID:ErikXu,项目名称:SimpleArticle,代码行数:5,代码来源:Global.asax.cs


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