// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddControllersWithViews(); services.AddRazorPages(); // Add services to the collection. Don't build or return // any IServiceProvider or the ConfigureContainer method // won't get called. //services.AddAutofac(); services.AddOptions(); // This adds the required middleware to the ROOT CONTAINER and is required for multitenancy to work. //AddAutofacMultitenantRequestServices(); //AutofacChildScopeServiceProviderFactory(); //AutofacChildLifetimeScopeConfigurationAdapter(); var factory = new AutofacChildLifetimeScopeServiceProviderFactory(AutofacContainer); var configurationAdapter = factory.CreateBuilder(services); var serviceProvider = factory.CreateServiceProvider(configurationAdapter); var builder = new ContainerBuilder(); foreach (var action in configurationAdapter.ConfigurationActions) { action(builder); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add services to the collection. Don't build or return // any IServiceProvider or the ConfigureContainer method // won't get called. //services.AddAutofac(); services.AddOptions( ); // This adds the required middleware to the ROOT CONTAINER and is required for multitenancy to work. //AddAutofacMultitenantRequestServices(); //AutofacChildScopeServiceProviderFactory(); // AutofacChildLifetimeScopeConfigurationAdapter(); var adapter = new AutofacChildLifetimeScopeConfigurationAdapter(); var actions = new AutofacChildLifetimeScopeConfigurationAdapter(); adapter.Add(builder => { }); actions.Add(builder => builder.Populate(services)); //AutofacContainer = services.BuildServiceProvider().GetAutofacRoot(); // Singleton BuildServiceProvider var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScope); var factory2 = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScopeWithDependency <IPrintMessages>(typeof(IPrintMessages))); var myServices = new ServiceCollection().AddTransient <IPrintMessages>(); services.AddSingleton <IPrintMessages>( ); var configurationAdapter = factory.CreateBuilder(services); var serviceProvider = factory.CreateServiceProvider(configurationAdapter); var builder = new ContainerBuilder(); foreach (var action in configurationAdapter.ConfigurationActions) { action(builder); } configurationAdapter.Add(builder => builder.RegisterType <IPrintMessages>( )); //var service = serviceProvider.GetRequiredService<IPrintMessages>(); }
public void CreateBuilderReturnsNewInstance() { var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScope); var configurationAdapter = factory.CreateBuilder(new ServiceCollection()); Assert.NotNull(configurationAdapter); }
public void CreateServiceProviderBuildsServiceProviderUsingAdapter() { var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScope); var services = new ServiceCollection().AddTransient <object>(); var configurationAdapter = factory.CreateBuilder(services); var serviceProvider = factory.CreateServiceProvider(configurationAdapter); Assert.NotNull(serviceProvider.GetService(typeof(object))); }
public void CreateServiceProviderAddDepToRootContainerResolveable() { var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScopeWithDependency <DependencyOne>(typeof(DependencyOne))); var configurationAdapter = factory.CreateBuilder(new ServiceCollection()); var serviceProvider = factory.CreateServiceProvider(configurationAdapter); serviceProvider.GetRequiredService <DependencyOne>(); }
public void CreateServiceProviderAddDepToServiceCollectionAndAddConfigurationTypesResolveable() { var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScope); var services = new ServiceCollection().AddTransient <DependencyOne>(); var configurationAdapter = factory.CreateBuilder(services); configurationAdapter.Add(builder => builder.RegisterType <DependencyTwo>()); var serviceProvider = factory.CreateServiceProvider(configurationAdapter); serviceProvider.GetRequiredService <DependencyOne>(); serviceProvider.GetRequiredService <DependencyTwo>(); }
public void CreateBuilderExecutesConfigurationActionWhenProvided() { var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScope, b => b.Register(c => "Foo")); var configurationAdapter = factory.CreateBuilder(new ServiceCollection()); var builder = new ContainerBuilder(); foreach (var action in configurationAdapter.ConfigurationActions) { action(builder); } Assert.Equal("Foo", builder.Build().Resolve <string>()); }
public void CreateBuilderReturnsInstanceWithServicesPopulated() { var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScope); var services = new ServiceCollection().AddTransient <object>(); var configurationAdapter = factory.CreateBuilder(services); var builder = new ContainerBuilder(); foreach (var action in configurationAdapter.ConfigurationActions) { action(builder); } Assert.True(builder.Build().IsRegistered <object>()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddControllersWithViews(); services.AddRazorPages(); // Add services to the collection. Don't build or return // any IServiceProvider or the ConfigureContainer method // won't get called. //services.AddAutofac(); services.AddOptions(); //services.AddSingleton<IServiceProviderFactory<ContainerBuilder>>(new AutofacServiceProviderFactory()); // This adds the required middleware to the ROOT CONTAINER and is required for multitenancy to work. //AddAutofacMultitenantRequestServices(); //AutofacChildScopeServiceProviderFactory(); // AutofacChildLifetimeScopeConfigurationAdapter(); var adapter = new AutofacChildLifetimeScopeConfigurationAdapter(); var actions = new AutofacChildLifetimeScopeConfigurationAdapter(); adapter.Add(builder => { }); actions.Add(builder => builder.Populate(services)); //AutofacContainer = services.BuildServiceProvider().GetAutofacRoot(); // Singleton BuildServiceProvider var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScope); var factory2 = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScopeWithDependency <IPrintMessages>(typeof(IPrintMessages))); var myServices = new ServiceCollection().AddTransient <IPrintMessages>(); services.AddSingleton <IPrintMessages>(); var configurationAdapter = factory.CreateBuilder(services); var serviceProvider = factory.CreateServiceProvider(configurationAdapter); var builder = new ContainerBuilder(); foreach (var action in configurationAdapter.ConfigurationActions) { action(builder); } configurationAdapter.Add(builder => builder.RegisterType <IPrintMessages>()); //var service = serviceProvider.GetRequiredService<IPrintMessages>(); }
public void ConfigureServices(IServiceCollection services) { var adapter = new AutofacChildLifetimeScopeConfigurationAdapter(); var actions = new AutofacChildLifetimeScopeConfigurationAdapter(); adapter.Add(builder => { }); actions.Add(builder => builder.Populate(services)); var factory = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScope); var factory2 = new AutofacChildLifetimeScopeServiceProviderFactory(GetRootLifetimeScopeWithDependency <IPrintMessages>(typeof(IPrintMessages))); var myServices = new ServiceCollection().AddTransient <IPrintMessages>(); services.AddSingleton <IPrintMessages>(); var configurationAdapter = factory.CreateBuilder(services); var serviceProvider = factory.CreateServiceProvider(configurationAdapter); var builder = new ContainerBuilder(); foreach (var action in configurationAdapter.ConfigurationActions) { action(builder); } configurationAdapter.Add(builder => builder.RegisterType <IPrintMessages>()); }