本文整理汇总了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();
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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());
}
示例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);
}
示例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();
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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;
}
示例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); ;
}