本文整理汇总了C#中Autofac.ContainerBuilder.ConfigureWebApi方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.ConfigureWebApi方法的具体用法?C# ContainerBuilder.ConfigureWebApi怎么用?C# ContainerBuilder.ConfigureWebApi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.ConfigureWebApi方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
builder.ConfigureWebApi(GlobalConfiguration.Configuration);
builder.RegisterApiControllers(_controllerAssembliesToScan);
}
示例2: SetAutofacWebAPIServices
private static void SetAutofacWebAPIServices()
{
var configuration = GlobalConfiguration.Configuration;
var builder = new ContainerBuilder();
// Configure the container with the integration implementations.
builder.ConfigureWebApi(configuration);
builder.RegisterType<DigitalAccountsUnitOfWork>()
.As<IDigitalAccountsUnitOfWork>()
.InstancePerLifetimeScope();
builder.RegisterType<DigitalAccountsService>()
.As<IDigitalAccountsService>()
.InstancePerLifetimeScope();
builder.RegisterAssemblyTypes(typeof(CuentaRepository).Assembly)
.Where(t => t.Name.EndsWith("Repository"))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
// Register API controllers using assembly scanning.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
var container = builder.Build();
// Set the dependency resolver implementation.
var resolver = new AutofacWebApiDependencyResolver(container);
configuration.ServiceResolver.SetResolver(resolver);
AutofacServiceHostFactory.Container = container;
}
示例3: Application_Start
protected void Application_Start()
{
HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
var configuration = GlobalConfiguration.Configuration;
var builder = new ContainerBuilder();
builder.ConfigureWebApi(configuration);
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.Register(c => CreateSessionFactory()).As<ISessionFactory>().SingleInstance();
builder.Register(c =>
{
var sf = c.Resolve<ISessionFactory>();
var session = sf.OpenSession();
var export = new SchemaExport(SavedConfig);
export.Execute(true, true, false, session.Connection, null);
return session;
}
).As<ISession>().SingleInstance();
builder.RegisterType<UnitOfWork>().InstancePerHttpRequest();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
var resolver = new AutofacWebApiDependencyResolver(container);
configuration.ServiceResolver.SetResolver(resolver);
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
}
示例4: Application_Start
protected void Application_Start()
{
//autofac
var configuration = GlobalConfiguration.Configuration;
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterModule(new AutofacModule());
builder.ConfigureWebApi(configuration);
builder.RegisterApiControllers(typeof (MvcApplication).Assembly);
var container = builder.Build();
var resolver = new AutofacWebApiDependencyResolver(container);
configuration.ServiceResolver.SetResolver(resolver);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
}
示例5: SetAutofacWebAPIServices
private static void SetAutofacWebAPIServices()
{
var configuration = GlobalConfiguration.Configuration;
var builder = new ContainerBuilder();
// Configure the container with the integration implementations.
builder.ConfigureWebApi(configuration);
// Register API controllers using assembly scanning.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterType<DefaultCommandBus>().As<ICommandBus>().InstancePerApiRequest();
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerApiRequest();
builder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerApiRequest();
builder.RegisterAssemblyTypes(typeof(CategoryRepository)
.Assembly).Where(t => t.Name.EndsWith("Repository"))
.AsImplementedInterfaces().InstancePerApiRequest();
var services = Assembly.Load("EFMVC.Domain");
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(ICommandHandler<>)).InstancePerApiRequest();
builder.RegisterAssemblyTypes(services)
.AsClosedTypesOf(typeof(IValidationHandler<>)).InstancePerApiRequest();
var container = builder.Build();
// Set the dependency resolver implementation.
var resolver = new AutofacWebApiDependencyResolver(container);
configuration.ServiceResolver.SetResolver(resolver);
}