本文整理汇总了C#中Autofac.ContainerBuilder.RegisterModelBinders方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterModelBinders方法的具体用法?C# ContainerBuilder.RegisterModelBinders怎么用?C# ContainerBuilder.RegisterModelBinders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.RegisterModelBinders方法的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: Load
protected override void Load(ContainerBuilder builder)
{
builder.RegisterModelBinders(_mvcModule);
builder.RegisterModelBinderProvider();
builder.RegisterControllers(_mvcModule);
builder.RegisterModule(new AutofacWebTypesModule());
}
示例3: 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));
}
示例4: Configure
public static void Configure()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterModelBinders(typeof(MvcApplication).Assembly);
builder
.Register(c => NHibernateConfig.SessionFactory.OpenSession())
.As<ISession>().InstancePerHttpRequest();
builder.RegisterType<CsvFileTextService<ForwardTextCandidate>>().As<ITextService<ForwardTextCandidate>>();
builder.RegisterType<CsvFileTextService<ReplyTextCandidate>>().As<ITextService<ReplyTextCandidate>>();
builder.RegisterType<Repository<ForwardTextCandidate>>().As<IBaseRepository<ForwardTextCandidate>>();
builder.RegisterType<Repository<ReplyTextCandidate>>().As<IBaseRepository<ReplyTextCandidate>>();
builder.Register<ServerStatusService>(c=>new ServerStatusService(NHibernateConfig.SessionFactory));
builder.RegisterType<UserService>();
builder.RegisterType<ServerProvidersAdminSettingsController>();
builder.RegisterType<UsersController>();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Create the dependency resolver.
var resolver = new AutofacWebApiDependencyResolver(container);
// Configure Web API with the dependency resolver.
GlobalConfiguration.Configuration.DependencyResolver = resolver;
}
示例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: 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);
}
示例7: 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));
}
示例8: 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));
}
示例9: 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));
}
示例10: 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;
}
示例11: 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();
}
示例12: 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();
}
示例13: 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();
}
示例14: RegisterTypes
public static void RegisterTypes()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(ContainerConfig).Assembly);
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
builder.RegisterModule<AutofacWebTypesModule>();
builder.RegisterSource(new ViewRegistrationSource());
builder.RegisterFilterProvider();
builder.Register(x => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.RegisterType<WorkaroundEmailService>().As<IEmailService>().SingleInstance();
RegisterServices(builder);
RegisterBackgroundTasks(builder);
builder.RegisterType<AuctioneerDbContext>().InstancePerRequest();
builder.RegisterType<BreadcrumbBuilder>().As<IBreadcrumbBuilder>().InstancePerDependency();
builder.RegisterType<AuthenticationManager>().As<IAuthenticationManager>().InstancePerRequest();
builder.RegisterType<EmailUserNotifier>().As<IUserNotifier>().SingleInstance();
builder.RegisterType<LanguageService>().As<ILanguageService>().SingleInstance();
builder.RegisterType<AuctionService>().As<IAuctionService>().InstancePerRequest().WithParameters(new Parameter[]
{
new NamedParameter("photoDirectoryPath", HostingEnvironment.MapPath("~/Content/UserContent/Auctions/Photos")),
new NamedParameter("thumbnailDirectoryPath", HostingEnvironment.MapPath("~/Content/UserContent/Auctions/Thumbnails"))
});
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
示例15: RegisterDependencies
public static void RegisterDependencies()
{
var builder = new ContainerBuilder();
builder.RegisterType<Config>().As<IConfig>();
builder.RegisterType<JsonConverter>().As<IConverter>().InstancePerRequest();
builder.RegisterType<CustomWebClient>().As<IWebClient>().InstancePerRequest();
builder.RegisterType<GitHubService>().As<IVcsService<GitHubUser, GitHubRepository>>().InstancePerRequest();
// 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));
}