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


C# ContainerBuilder.RegisterWebApiFilterProvider方法代码示例

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


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

示例1: Configuration

        public void Configuration(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            GlobalConfiguration.Configure(WebApiConfig.Register);

            var config = GlobalConfiguration.Configuration;
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterHubs(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(config);
            builder.RegisterHubs(Assembly.GetExecutingAssembly());
            builder.RegisterInstance(new GameService()).As<IGameService>().SingleInstance();
            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            GlobalHost.DependencyResolver = new AutofacDependencyResolver(container);

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

            var hubConfig = new HubConfiguration();
            hubConfig.Resolver = new AutofacDependencyResolver(container);

            app.UseAutofacMiddleware(container);
            app.MapSignalR();
        }
开发者ID:gobixm,项目名称:learn,代码行数:27,代码来源:OwinStartup.cs

示例2: Application_Start

        protected void Application_Start()
        {
            var config = GlobalConfiguration.Configuration;

            config.MapHttpAttributeRoutes();
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;

            config.Filters.Add(new BadRequestExceptionAttribute());
            config.Filters.Add(new NotFoundExceptionAttribute());
            config.Filters.Add(new AuthAttribute());
            config.Filters.Add(new ValidationFilterAttribute());

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterFilters(config);

            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(config);

            RegisterHandlers(builder);
            RegisterContext(builder);

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

            FluentValidationModelValidatorProvider.Configure(config);

            config.EnsureInitialized();

            TestsContext.SetInitializer();
            ConfigureMappings();
        }
开发者ID:ddraganov,项目名称:FMI-WebDev2015,代码行数:33,代码来源:Global.asax.cs

示例3: Register

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute("DefaultApi",
                "api/{controller}/{id}",
                new {id = RouteParameter.Optional}
                );

            var builder = new ContainerBuilder();

            builder.RegisterType<ConsoleLogger>().As<ILogger>();

            builder.Register(c => new LoggingActionFilter(c.Resolve<ILogger>())).
                AsWebApiActionFilterFor<ValuesController>(c => c.Get())
                .InstancePerRequest();

            var globalConfiguration = GlobalConfiguration.Configuration;
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(config);

            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
开发者ID:IcodeNet,项目名称:WebApiAutofac,代码行数:27,代码来源:WebApiConfig.cs

示例4: Config

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

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

            // Register dependencies in filter attributes
            builder.RegisterFilterProvider();

            // Register dependencies in custom views
            builder.RegisterSource(new ViewRegistrationSource());

            // Get your HttpConfiguration.
            var config = GlobalConfiguration.Configuration;

            // Register your Web API controllers.
            builder.RegisterApiControllers(typeof(ReservationController).Assembly);

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

            builder.RegisterModule(new ManagerModule());

            var container = builder.Build();
            var webApiResolver = new AutofacWebApiDependencyResolver(container);
            // Mechanism for setting the dependency resolver for Web API and MVC is different.
            // Web API uses GlobalConfiguration.Configuration.DependencyResolver
            GlobalConfiguration.Configuration.DependencyResolver = webApiResolver;

            var mvcResolver = new AutofacDependencyResolver(container);
            DependencyResolver.SetResolver(mvcResolver);
        }
开发者ID:pasha369,项目名称:RestaurantManagementSystem,代码行数:33,代码来源:AutofacConfig.cs

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

示例6: Init

        internal static void Init()
        {
            var builder = new ContainerBuilder();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

            //builder.RegisterInstance<CachedJsonFileStore>(new CachedJsonFileStore()).AsImplementedInterfaces();
            builder.RegisterInstance<InMemoryStore>(new InMemoryStore()).AsImplementedInterfaces();

            //builder.RegisterType<DummyAuthenticator>().AsImplementedInterfaces();
            builder.RegisterType<ActiveDirectoryAuthenticator>().AsImplementedInterfaces();

            builder.RegisterType<AuthorizationFilter>()
                .AsWebApiAuthorizationFilterFor<ReservationController>(c => c.Post(default(Reservation)))
                .InstancePerApiRequest();
            builder.RegisterType<AuthorizationFilter>()
                .AsWebApiAuthorizationFilterFor<ReservationController>(c => c.Put(default(Guid), default(Reservation)))
                .InstancePerApiRequest();
            builder.RegisterType<AuthorizationFilter>()
                .AsWebApiAuthorizationFilterFor<ReservationController>(c => c.Delete(default(Guid)))
                .InstancePerApiRequest();

            GlobalConfiguration.Configuration.DependencyResolver =
                new AutofacWebApiDependencyResolver(builder.Build());
        }
开发者ID:hinteadan,项目名称:croom,代码行数:25,代码来源:Dependencies.cs

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

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

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

示例10: Configuration

        public void Configuration(IAppBuilder app)
        {
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            var builder = new ContainerBuilder();
            var config = new HttpConfiguration();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            builder.RegisterType<InstantDeliveryContext>()
                .AsSelf()
                .As<DbContext>() // for UserStore
                .InstancePerLifetimeScope();

            builder.Register(c => new RegularPricingStrategy())
                .AsImplementedInterfaces()
                .SingleInstance();

            RegisterIdentity(app, builder);

            builder.RegisterWebApiFilterProvider(config);

            WebApiConfig.Register(config);

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

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);

            // has to be called before UseWebApi
            ConfigureOAuth(app);

            app.UseWebApi(config);
        }
开发者ID:mchudy,项目名称:InstantDelivery,代码行数:34,代码来源:Startup.cs

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

示例12: Register

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            config.Filters.Add(new ExceptionAttribute());
            config.Filters.Add(new ValidationAttribute());

            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            // Web API routes
            config.MapHttpAttributeRoutes();

            // all routes with ~/api should be resolved by web api
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            #if DEBUG
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
            #else
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never;
            #endif

            var builder = new ContainerBuilder();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(config);
            RegisterData(builder);
            RegisterServices(builder);
            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            config.EnsureInitialized();
        }
开发者ID:ivailok,项目名称:Haiku,代码行数:34,代码来源:WebApiConfig.cs

示例13: Application_Start

        protected void Application_Start()
        {
            MvcHandler.DisableMvcResponseHeader = true;

            log4net.Config.XmlConfigurator.Configure();

            BootStrapper.BootStrap();
            var container = BootStrapper.Container;

            var builder = new ContainerBuilder();
            var config = GlobalConfiguration.Configuration;

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(config);

            builder.Update(container);
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            AreaRegistration.RegisterAllAreas();

            // fluent validation
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
            GlobalConfiguration.Configuration.Services.Add(typeof(System.Web.Http.Validation.ModelValidatorProvider), new FluentValidationModelValidatorProvider(new ValidatorFactory()));

            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
开发者ID:coolworker,项目名称:yue,代码行数:28,代码来源:Global.asax.cs

示例14: BuildAutofacContainer

        private static IContainer BuildAutofacContainer()
        {
            var builder = new ContainerBuilder();
            var assemblies = GetAssemblies();

            builder.RegisterApiControllers(assemblies);
            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

            builder.RegisterType<CommandDispatcher>().As<ICommandDispatcher>().InstancePerRequest();
            //builder.Register(c => new WebApiCommandResolver() as HttpContextBase).As<HttpContextBase>().InstancePerRequest();
            builder.RegisterType<WebApiCommandResolver>().As<ICommandHandlerResolver>().InstancePerRequest();
            builder.RegisterType<JsonEventSerializer>().As<IEventSerializer>().InstancePerRequest();
            builder.RegisterType<MassTransitEventPublisher>().As<IEventPublisher>().SingleInstance();
            builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerRequest();
            builder.RegisterType<MySqlEventStore>().As<IEventStore>().InstancePerRequest();
            builder.RegisterType<DomainRepository>().As<IDomainRepository>().InstancePerRequest();
            builder.RegisterType<RegisterUserHandler>().As<ICommandHandler<RegisterUserCommand>>().InstancePerRequest();
            builder.RegisterType<RegisterExternalUserHandler>().As<ICommandHandler<RegisterExternalUserCommand>>().InstancePerRequest();

            builder.RegisterType<EncryptionService>().As<IEncryptionService>().InstancePerRequest();
            builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().InstancePerRequest();

            builder.RegisterType<UserApplicationService>().As<IUserApplicationService>().InstancePerRequest();

            builder.RegisterType<UserQueryService>().As<IUserQueryService>().InstancePerRequest();

            SetUpMassTransit(builder);

            IContainer container = builder.Build();

            return container;
        }
开发者ID:vitorsalgado,项目名称:crap,代码行数:32,代码来源:DependencyResolverFactory.cs

示例15: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //Autofac
            // Create the container builder.
            var builder = new ContainerBuilder();

            // Register the Web API controllers.
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
            // Register other dependencies.
            //builder.Register(c => new Logger()).As<ILogger>().InstancePerApiRequest();

            // Build the container.
            IContainer container = builder.Build();

            // Create the depenedency resolver.
            //var resolver =

            // Configure Web API with the dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container); ;
        }
开发者ID:rupampatel2006,项目名称:fn,代码行数:27,代码来源:Global.asax.cs


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