本文整理汇总了C#中Autofac.ContainerBuilder.RegisterModelBinderProvider方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterModelBinderProvider方法的具体用法?C# ContainerBuilder.RegisterModelBinderProvider怎么用?C# ContainerBuilder.RegisterModelBinderProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.RegisterModelBinderProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterAutofac
public static void RegisterAutofac()
{
var builder = new ContainerBuilder();
// Register your MVC controllers.
// If AutofacConfig's assembly doesn't reference the specific controllers assemblies, use these:
// builder.RegisterControllers(typeof(MvcApplication).Assembly);
// builder.RegisterControllers(typeof(BasePublicController).Assembly);
// builder.RegisterControllers(typeof(BaseAdminController).Assembly);
// ...
builder.RegisterControllers(BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray());
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
// Register services
RegisterServices(builder);
// Set the dependency resolver to be Autofac.
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Integration with Hangfire
GlobalConfiguration.Configuration.UseAutofacActivator(container);
}
示例2: BuildMvcContainer
/// <summary>
/// 创建 MVC容器(包含Filter)
/// </summary>
public static void BuildMvcContainer()
{
var builder = new ContainerBuilder();
//注册Module方法2 在Web.config中配制方式
builder.RegisterModule(new ConfigurationSettingsReader("autofacMvc"));
//加载 *.Controllers 层的控制器,否则无法在其他层控制器构造注入,只能在web层注入
Assembly[] asm = GetAllAssembly("*.Controllers.dll").ToArray();
builder.RegisterAssemblyTypes(asm);
//注册仓储
Assembly[] asmRepository = GetAllAssembly("*.Repository.dll").ToArray();
builder.RegisterAssemblyTypes(asmRepository)
.Where(t => t.Name.EndsWith("Repository"))
.AsImplementedInterfaces();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
//注册过滤器
builder.RegisterFilterProvider();
builder.RegisterType<OperateAttribute>().PropertiesAutowired();//非global filter 属性注入
builder.RegisterType<GlobalFilterAttribute>().SingleInstance();//global filter 注入
builder.RegisterControllers(typeof(MvcApplication).Assembly);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
示例3: Load
protected override void Load(ContainerBuilder builder)
{
builder.RegisterModelBinders(_mvcModule);
builder.RegisterModelBinderProvider();
builder.RegisterControllers(_mvcModule);
builder.RegisterModule(new AutofacWebTypesModule());
}
示例4: 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);
}
示例5: RegisterAutofac
public static void RegisterAutofac()
{
var builder = new ContainerBuilder();
// Register your MVC controllers.
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
// Register services
RegisterServices(builder);
// Set the dependency resolver to be Autofac.
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
示例6: BuildContainer
public static void BuildContainer()
{
var builder = new ContainerBuilder();
// Register your MVC controllers.
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
// Add our own components
builder.RegisterType<NameResolver>().As<INameResolver>();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(x=>x.Name.EndsWith("Service"))
.AsImplementedInterfaces();
// Set the dependency resolver to be Autofac.
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
示例7: Application_Start
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
var builder = new ContainerBuilder();
builder.RegisterModelBinderProvider();
builder.RegisterModule(new AutofacWebTypesModule());
builder.RegisterSource(new ViewRegistrationSource());
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterType<InMemoryPersonRepository>().As<IPersonRepository>();
// Use application-scoped variable to mimic in-memory database
var personDatabase = new List<Person>();
builder.Register(c => personDatabase).As<List<Person>>();
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
ModelMetadataProviders.Current = new MetadataProvider();
}
示例8: UseAutofacInjection
public static IAppBuilder UseAutofacInjection(this IAppBuilder app, HttpConfiguration httpConfiguration)
{
var currentAssembly = Assembly.GetExecutingAssembly();
var builder = new ContainerBuilder();
// Web API
builder.RegisterApiControllers(currentAssembly);
builder.RegisterWebApiFilterProvider(httpConfiguration);
// MVC
builder.RegisterControllers(currentAssembly).PropertiesAutowired();
builder.RegisterModelBinders(currentAssembly);
builder.RegisterModelBinderProvider();
builder.RegisterModule<AutofacWebTypesModule>();
//builder.RegisterSource(new ViewRegistrationSource());
builder.RegisterFilterProvider();
builder.RegisterAssemblyModules(currentAssembly);
// Hook it up
var container = builder.Build();
httpConfiguration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Register the Autofac middleware FIRST, then the Autofac MVC middleware.
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
return app;
}
示例9: BuildAutofacContainer
private static IContainer BuildAutofacContainer(IAppBuilder app)
{
var builder = new ContainerBuilder();
// Register your MVC controllers.
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
//Register Dependencies
RegisterIdentityParts(app, builder);
RegisterImageParts(app, builder);
RegisterContentParts(app, builder);
return builder.Build();
}
示例10: 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;
}
示例11: Setup
public static void Setup()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
// Register for API Controllers
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterFilterProvider();
builder.RegisterModelBinderProvider();
builder.RegisterModule<AutofacWebTypesModule>();
// Find all autofac modules and include them.
builder.RegisterModule<IdentityModule>();
// Find all IStartable tasks and register them.
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
builder.RegisterAssemblyTypes(assemblies)
.AssignableTo<IStartable>()
.As<IStartable>()
.SingleInstance();
// Enable property injection into action filters (including authorize attribute).
builder.RegisterFilterProvider();
IContainer container = builder.Build();
var resolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
示例12: Config
public static void Config()
{
var builder = new ContainerBuilder();
// Register MVC controllers.
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
var container = Bootstrap.ServiceLocator.Instance.InitializeIOC(builder);
// Set the dependency resolver to be Autofac.
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
示例13: RegisterServices
protected void RegisterServices()
{
var tenantIdStrategy = new RouteDataItemTenantIdentificationStrategy("tenant");
var builder = new ContainerBuilder();
// Register your MVC controllers.
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
// Create the multitenant container and the tenant overrides.
var mtc = new MultitenantContainer(tenantIdStrategy, builder.Build());
AddTenant(mtc, "a");
AddTenant(mtc, "b");
DependencyResolver.SetResolver(new AutofacDependencyResolver(mtc));
}
示例14: RegisterBindings
public static void RegisterBindings()
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterModule(new Vintage.Rabbit.CQRS.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Carts.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Common.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Products.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Caching.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Messaging.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Orders.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Membership.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Inventory.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Blogs.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Themes.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Search.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Logging.Ioc.Bindings());
builder.RegisterModule(new Vintage.Rabbit.Parties.Ioc.Bindings());
builder.RegisterType<LoginProvider>().As<ILoginProvider>();
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
builder.RegisterFilterProvider();
builder.RegisterType<HandleExceptionAttribute>().AsExceptionFilterFor<Controller>().InstancePerRequest().PropertiesAutowired();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
示例15: Application_Start
protected void Application_Start()
{
var builder = new ContainerBuilder();
BuildMappings(builder);
// Register your MVC controllers.
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
// Set the dependency resolver to be Autofac.
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ConfigureLogging();
}