本文整理汇总了C#中Autofac.ContainerBuilder.Populate方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.Populate方法的具体用法?C# ContainerBuilder.Populate怎么用?C# ContainerBuilder.Populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.Populate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public IServiceProvider ConfigureServices(IServiceCollection services)
{
var bootstrapper = new MyBootstrapper();
var builder = new ContainerBuilder();
builder.Populate(bootstrapper);
builder.Populate(services);
Container = builder.Build();
return Container.Resolve<IServiceProvider>();
}
示例2: ConfigureServices
// This method gets called by a runtime.
// Use this method to add services to the container
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var builder = new ContainerBuilder();
builder.RegisterType<ConcreteCacheProvider>().As<ICacheProvider>();
builder.RegisterType<SerilogLoggerFactory>().As<ILoggerFactory>();
builder.RegisterType(typeof(ThingyRepository)).Named<IRepository<Thingy>>("repository");
builder.RegisterGenericDecorator(
typeof(CachedRepository<>),
typeof(IRepository<>),
fromKey: "repository")
.Keyed("decorated", typeof(IRepository<>));
builder.RegisterGenericDecorator(
typeof(PerformanceLoggingRepository<>),
typeof(IRepository<>),
fromKey: "decorated");
builder.Populate(services);
var container = builder.Build();
return container.ResolveOptional<IServiceProvider>();
}
示例3: CreateAutofacContainer
public static ILifetimeScope CreateAutofacContainer(this IServiceCollection services, IConfigurationRoot configuration)
{
var builder = new ContainerBuilder();
// Load web specific dependencies
builder.RegisterType<AuthMessageSender>()
.As<IEmailSender>().InstancePerLifetimeScope();
builder.RegisterAssemblyTypes(typeof(Startup).GetTypeInfo().Assembly).AsImplementedInterfaces();
builder.RegisterAssemblyTypes(typeof (CartCommandService).GetTypeInfo().Assembly, typeof (ICartCommandService).GetTypeInfo().Assembly)
.AsImplementedInterfaces();
var databaseInitializer = new MigrateToLatestVersion(new SampleDataSeeder());
builder.AddDataOnion(new DbContextConfig(configuration.GetConnectionString("DefaultConnection"), typeof(MusicStoreContext), databaseInitializer));
// Populate the container with services that were previously registered
builder.Populate(services);
builder.RegisterType<BaseRepository<Album, MusicStoreContext>>().As<IRepository<Album>>();
builder.RegisterType<BaseRepository<Artist, MusicStoreContext>>().As<IRepository<Artist>>();
builder.RegisterType<BaseRepository<Cart, MusicStoreContext>>().As<IRepository<Cart>>();
builder.RegisterType<BaseRepository<CartItem, MusicStoreContext>>().As<IRepository<CartItem>>();
builder.RegisterType<BaseRepository<Genre, MusicStoreContext>>().As<IRepository<Genre>>();
builder.RegisterType<BaseRepository<Order, MusicStoreContext>>().As<IRepository<Order>>();
builder.RegisterType<BaseRepository<OrderDetail, MusicStoreContext>>().As<IRepository<OrderDetail>>();
var container = builder.Build();
return container;
}
示例4: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Create the Autofac container builder.
var builder = new ContainerBuilder();
// Add any Autofac modules or registrations.
builder.RegisterModule(new ServiceModule());
// Populate the services.
builder.Populate(services);
// Build the container.
var container = builder.Build();
// Resolve and return the service provider.
return container.Resolve<IServiceProvider>();
}
示例5: Configure
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseServices(services =>
{
// We add MVC here instead of in ConfigureServices.
services.AddMvc();
// Create the Autofac container builder.
var builder = new ContainerBuilder();
// Add any Autofac modules or registrations.
builder.RegisterModule(new AutofacModule());
// Populate the services.
builder.Populate(services);
// Build the container.
var container = builder.Build();
// Resolve and return the service provider.
return container.Resolve<IServiceProvider>();
});
app.UseStaticFiles();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
示例6: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
// Inject services to application.
var mvcBuilder = services.AddMvc();
/*mvcBuilder.AddMvcOptions(option =>
{
option.OutputFormatters.OfType<JsonOutputFormatter>()
.First()
.SerializerSettings
.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
*/
// Create the Autofac container builder.
var builder = new ContainerBuilder();
// Add any Autofac modules or registrations.
builder.RegisterModule(new BusinessModule());
builder.RegisterModule(new SharedModule());
// Populate the services.
builder.Populate(services);
// Build the container.
var container = builder.Build();
// Resolve and return the service provider.
return container.Resolve<IServiceProvider>();
}
示例7: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
#region Token Bearer
services.AddJwtAuthentication(Path.Combine(_env.ContentRootPath, "./Security"), "RsaKey.json", "noobs", "http://leadisjourney.fr");
#endregion
services.AddNHibernate(Configuration.GetConnectionString("type"), Configuration.GetConnectionString("DefaultConnection"));
// Add framework services.
services.AddMvc();
services.AddCors(option => option.AddPolicy("AllowAll", p =>
{
p.AllowAnyOrigin();
p.AllowCredentials();
p.AllowAnyMethod();
p.AllowAnyHeader();
}));
// Adding ioc Autofac
var containerBuilder = new ContainerBuilder();
containerBuilder.Populate(services);
containerBuilder.RegisterModule<GlobalRegistration>();
var container = containerBuilder.Build();
return container.Resolve<IServiceProvider>();
}
示例8: ConfigureServices
public IServiceProvider ConfigureServices(IServiceCollection services)
{
var builder1 = new ContainerBuilder();
builder1.RegisterModule<TestModule>();
builder1.Populate(services);
var container1 = builder1.Build();
var nonScopeOptions = container1.Resolve<IServiceProvider>()
.GetService<Microsoft.Framework.OptionsModel.IOptions<RazorViewEngineOptions>>()
.Options;
Console.WriteLine("{0} Options", nonScopeOptions.ViewLocationExpanders.Count);
Console.WriteLine("");
var builder2 = new ContainerBuilder();
builder2.Populate(services);
var container2 = builder2.Build();
var scope = container2.BeginLifetimeScope((inner) => {
inner.RegisterModule<TestModule>();
}).Resolve<IServiceProvider>();
var scopeOptions = scope
.GetService<Microsoft.Framework.OptionsModel.IOptions<RazorViewEngineOptions>>()
.Options;
Console.WriteLine("{0} Options", scopeOptions.ViewLocationExpanders.Count);
return container1.Resolve<IServiceProvider>();
}
示例9: ConfigureServices
/// <summary>
/// Sets up the DI container. Loads types dynamically (http://docs.autofac.org/en/latest/register/scanning.html)
/// </summary>
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
/* TODO: #10
services.AddCaching();
services.AddSession();
services.ConfigureSession(o =>
{
o.IdleTimeout = TimeSpan.FromMinutes(5);
});*/
services.AddTransient<WopiAuthorizationAttribute>();
// Autofac resolution
var builder = new ContainerBuilder();
// Configuration
Configuration configuration = new Configuration();
configuration.AddEnvironmentVariables();
builder.RegisterInstance(configuration).As<IConfiguration>().SingleInstance();
// File provider implementation
var providerAssembly = configuration.Get("WopiFileProviderAssemblyName");
var assembly = AppDomain.CurrentDomain.Load(new AssemblyName(providerAssembly));
builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces();
builder.Populate(services);
var container = builder.Build();
return container.Resolve<IServiceProvider>();
}
示例10: GetAppContainer
public static IAppContainer GetAppContainer(IServiceCollection services)
{
var builder = new ContainerBuilder();
builder.RegisterModule<DefaultModule>();
builder.Populate(services);
return new AppContainer(builder.Build());
}
示例11: BuildAndSetResolver
/// <summary>
/// 构建服务并设置本地程序平台的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.Populate(services);
IContainer container = builder.Build();
LocalIocResolver.Container = container;
Resolver = container.Resolve<IIocResolver>();
return Resolver.Resolve<IServiceProvider>();
}
示例12: CreateContainer
protected override IServiceProvider CreateContainer()
{
var builder = new ContainerBuilder();
builder.Populate(TestServices.DefaultServices());
IContainer container = builder.Build();
return container.Resolve<IServiceProvider>();
}
示例13: CreateIoCContainer
private IContainer CreateIoCContainer(IServiceCollection services)
{
services.AddTransient<IEmailSender, EmailSender>();
var containerBuilder = new ContainerBuilder();
containerBuilder.Populate(services);
return containerBuilder.Build();
}
示例14: BuildAndSetResolver
/// <summary>
/// 构建服务并设置SignalR平台的Resolver
/// </summary>
/// <param name="services">服务映射信息集合</param>
/// <param name="assemblies">要检索的程序集集合</param>
protected override IServiceProvider BuildAndSetResolver(IServiceCollection services, Assembly[] assemblies)
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterHubs().AsSelf().PropertiesAutowired();
builder.Populate(services);
IContainer container = builder.Build();
IDependencyResolver resolver = new AutofacDependencyResolver(container);
GlobalHost.DependencyResolver = resolver;
return resolver.Resolve<IServiceProvider>();
}
示例15: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
//public void ConfigureServices(IServiceCollection services)
//{
// services.AddMvc();
// services.AddSingleton<IService<EmployeeInfo>, EmployeeInfoService>();
//}
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var objectBuilder = new ContainerBuilder();
objectBuilder.RegisterModule<DependencyRegistrationModule>();
objectBuilder.Populate(services);
var objectContainer = objectBuilder.Build();
return objectContainer.Resolve<IServiceProvider>();
}