本文整理汇总了C#中IAppBuilder.UseAutofacMvc方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.UseAutofacMvc方法的具体用法?C# IAppBuilder.UseAutofacMvc怎么用?C# IAppBuilder.UseAutofacMvc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAppBuilder
的用法示例。
在下文中一共展示了IAppBuilder.UseAutofacMvc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configuration
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
var assemblies = BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToArray();
builder.RegisterType<Entities>().As<IDbContext>().InstancePerLifetimeScope();
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerLifetimeScope();
builder.RegisterAssemblyTypes(typeof(IRepository<>).Assembly).AsClosedTypesOf(typeof(IRepository<>)).InstancePerRequest();
builder.RegisterAssemblyTypes(ServiceAssembly).Where(type => typeof(ServiceBase).IsAssignableFrom(type) && !type.IsAbstract).AsImplementedInterfaces().InstancePerRequest();
builder.RegisterAssemblyTypes(MapperAssembly).Where(type => typeof(MapperBase).IsAssignableFrom(type) && !type.IsAbstract).AsImplementedInterfaces().InstancePerRequest();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerRequest();
builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IdentityRole, string>>().InstancePerRequest();
builder.RegisterType<ApplicationRoleManager>().AsSelf().InstancePerRequest();
builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.Register(c => app.GetDataProtectionProvider()).InstancePerRequest();
builder.RegisterModule(new LoggingModule());
builder.RegisterControllers(assemblies);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
ConfigureAuth(app);
}
示例2: Configuration
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
var container = ConfigureAutoFac.ConfigureMvc();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
//Dit op Configure laten staan, dit wordt namelijk niet in web requests gebruikt
// Remove the old formatter, add the new one.
var formatter = new JsonMediaTypeFormatter();
formatter.SerializerSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
config.Formatters.Remove(config.Formatters.JsonFormatter);
config.Formatters.Add(formatter);
config.Formatters.Remove(config.Formatters.XmlFormatter);
WebApiConfig.Register(config);
app.UseCors(CorsOptions.AllowAll);
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
app.UseAutofacWebApi(config);
app.UseWebApi(config);
ConfigureAuth(app);
}
示例3: Configuration
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
// REGISTER DEPENDENCIES
builder.RegisterType<OnlineLibDbContext>().AsSelf().InstancePerRequest();
builder.RegisterType<LibRoleStore>().As<IRoleStore<LibRole, Guid>>().InstancePerRequest();
builder.RegisterType<LibUserStore>().As<IUserStore<LibUser, Guid>>().InstancePerRequest();
builder.RegisterType<LibUserManager>().AsSelf().InstancePerRequest();
builder.RegisterType<LinRoleManager>().AsSelf().InstancePerRequest();
builder.RegisterType<LibSignInManager>().AsSelf().InstancePerRequest();
builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.Register(c => app.GetDataProtectionProvider()).InstancePerRequest();
builder.RegisterType<LibraryRepository>().As<ILibraryRepository>().InstancePerRequest();
builder.RegisterType<BooksRepository>().As<IBooksRepository>().InstancePerRequest();
builder.RegisterType<EmailService>().As<IIdentityMessageService>().InstancePerRequest();
// REGISTER CONTROLLERS
// builder.RegisterControllers<AccountController>(typeof (ILibraryRepository)).AsSelf().InstancePerRequest();
builder.RegisterControllers(typeof (MvcApplication).Assembly);
// BUILD CONTAINER
var container = builder.Build();
// SET AUTOFAC DEPENDENCY RESOLVER
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// REGISTER AUTOFAC WITH OWIN
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
ConfigureAuth(app);
}
示例4: Configure
public static void Configure(IAppBuilder app)
{
var builder = new ContainerBuilder();
// Register controllers
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterControllers(Assembly.GetExecutingAssembly());
// Register repositories
builder.RegisterType<ProductRepository>().As<IProductRepository>();
builder.RegisterType<CurrencyRepository>().As<IRepositoryAsync<CurrencyRate>>();
// Register services
builder.RegisterType<CurrencyService>().As<ICurrencyService>();
// Register data context
builder.RegisterType<DHUEntities>().InstancePerRequest();
builder.Register(c => new DHUEntities()).InstancePerLifetimeScope();
var container = builder.Build();
// Set the MVC and the WebApi dependency resolver.
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
}
示例5: Configuration
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
var config = new HttpConfiguration();
// Identity Dependencies
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerLifetimeScope();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerLifetimeScope();
builder.Register<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication);
// Web Application Dependencies
builder.RegisterType<StoreContext>().AsSelf().InstancePerRequest();
builder.RegisterType<StoreItemService>().AsSelf();
builder.RegisterType<ReceivingItemService>().AsSelf();
// Autofac MVC Boilerplate
builder.RegisterModule<AutofacWebTypesModule>();
builder.RegisterFilterProvider();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
//Autofac WebAPI2 Boilerplate
builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
builder.RegisterWebApiFilterProvider(config);
var container = builder.Build();
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
app.UseAutofacWebApi(config);
ConfigureAuth(app);
}
示例6: Configuration
public void Configuration(IAppBuilder app)
{
// Loads the config from our App.config
XmlConfigurator.Configure();
// MassTransit to use Log4Net
Log4NetLogger.Use();
var container = IocConfig.RegisterDependencies();
// Sets the Mvc resolver
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Sets Mvc Owin resolver as well
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
// Starts Mass Transit Service bus, and registers stopping of bus on app dispose
var bus = container.Resolve<IBusControl>();
var busHandle = bus.StartAsync().Result;
if (app.Properties.ContainsKey("host.OnAppDisposing"))
{
var context = new OwinContext(app.Properties);
var token = context.Get<CancellationToken>("host.OnAppDisposing");
if (token != CancellationToken.None)
{
token.Register(() => busHandle.Stop(TimeSpan.FromSeconds(30)));
}
}
}
示例7: Configuration
public void Configuration(IAppBuilder app)
{
var configuration = new ConfigurationService();
var builder = new ContainerBuilder();
builder.Register(c => configuration).As<ConfigurationService>().SingleInstance();
builder.Register(c => configuration.CurrentConfiguration).As<AppConfiguration>().SingleInstance();
builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
var container = AutofacBootstrapper.Initialize(builder);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Must register Autofac middleware FIRST!
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
ConfigureAuth(app, configuration.CurrentConfiguration);
AntiForgeryConfig.UniqueClaimTypeIdentifier = JwtClaimTypes.Subject;
AntiForgeryConfig.RequireSsl = true;
AntiForgeryConfig.CookieName = Prsd.Core.Web.Constants.CookiePrefix + Constants.AntiForgeryCookieName;
MvcHandler.DisableMvcResponseHeader = true;
}
示例8: Configuration
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
// REGISTER DEPENDENCIES
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<ApplicationUser>>().InstancePerRequest();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerRequest();
builder.Register<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
builder.Register<IDataProtectionProvider>(c => app.GetDataProtectionProvider()).InstancePerRequest();
// REGISTER CONTROLLERS SO DEPENDENCIES ARE CONSTRUCTOR INJECTED
builder.RegisterControllers(typeof(MvcApplication).Assembly);
// BUILD THE CONTAINER
var container = builder.Build();
// REPLACE THE MVC DEPENDENCY RESOLVER WITH AUTOFAC
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// REGISTER WITH OWIN
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
ConfigureAuth(app);
}
示例9: Configuration
public void Configuration(IAppBuilder app)
{
var configuration = new ConfigurationService();
var builder = new ContainerBuilder();
builder.Register(c => configuration).As<ConfigurationService>().SingleInstance();
builder.Register(c => configuration.CurrentConfiguration).As<IAppConfiguration>().SingleInstance();
builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
var container = AutofacBootstrapper.Initialize(builder);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Must register Autofac middleware FIRST!
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
ConfigureAuth(app, configuration.CurrentConfiguration);
AntiForgeryConfig.UniqueClaimTypeIdentifier = JwtClaimTypes.Subject;
AntiForgeryConfig.RequireSsl = true;
AntiForgeryConfig.CookieName = Prsd.Core.Web.Constants.CookiePrefix + Constants.AntiForgeryCookieName;
MvcHandler.DisableMvcResponseHeader = true;
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ModelBinders.Binders.DefaultBinder = new TrimModelBinder();
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RequiredAttribute), typeof(WeeeRequiredAttributeAdapter));
ApplicationVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
示例10: ConfigureContainer
public static void ConfigureContainer(IAppBuilder app)
{
IContainer container = CreateContainer();
app.UseAutofacMiddleware(container);
// Register MVC Types
app.UseAutofacMvc();
}
示例11: Configuration
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
var container = AutofacBootstrapper.GetContainer();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
}
示例12: Bootstrap
public static void Bootstrap(IAppBuilder app)
{
var mvcContainer = ConfigureMvcContainer();
app.UseAutofacMiddleware(mvcContainer);
app.UseAutofacWebApi(GlobalConfiguration.Configuration);
app.UseAutofacMvc();
}
示例13: Configure
public static void Configure(IAppBuilder app)
{
IContainer container = BuildAutofacContainer(app);
// Set the dependency resolver to be Autofac.
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Register the Autofac middleware FIRST, then the Autofac MVC middleware.
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
}
示例14: Configuration
public void Configuration(IAppBuilder app)
{
var builder = new ContainerBuilder();
var container = AutofacConfig.BuildContainer(builder);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
}
示例15: RegisterDependencyInjection
private void RegisterDependencyInjection(IAppBuilder app, IContainer container)
{
// Enable Autofac for MVC and WebAPI
app.UseAutofacMvc();
app.UseAutofacWebApi(GlobalConfiguration.Configuration);
// Set MVC5 dependency resolver
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// Set API2 dependency resolver
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
// Set OWIN dependency resolver
app.UseAutofacMiddleware(container);
}