本文整理汇总了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;
}
示例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();
}
示例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();
}
示例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);
}
示例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));
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例10: RegisterModelBinders
private static void RegisterModelBinders(ContainerBuilder builder)
{
builder.RegisterWebApiModelBinderProvider();
builder.RegisterType<ObjectIdModelBinder>().AsModelBinderForTypes(typeof(ObjectId));
}