// 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 AddMultipleConfigurationContainsConfigurations()
        {
            var adapter = new AutofacChildLifetimeScopeConfigurationAdapter();

            adapter.Add(builder => { });
            adapter.Add(builder => { });

            Assert.Equal(2, adapter.ConfigurationActions.Count);
        }
Beispiel #3
0
 /// <summary>
 /// This method is called by the <see cref="IHost"/> since we are registering <see cref="AutofacChildLifetimeScopeServiceProviderFactory"/> for Host B.
 /// </summary>
 /// <param name="configurationAdapter">An adapter that can take several registrations for the scope used in Application B.</param>
 public void ConfigureContainer(AutofacChildLifetimeScopeConfigurationAdapter configurationAdapter)
 {
     // You must use an AutofacChildLifetimeScopeConfigurationAdapter
     // here instead of a ContainerBuilder.
     configurationAdapter.Add(
         builder => builder
         .RegisterType <ApplicationBScopedDependency>()
         .AsSelf()
         .InstancePerLifetimeScope()
         );
 }
Beispiel #4
0
        // 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>());
        }
Beispiel #6
0
 // Here's the change for child lifetime scope usage! Register your "root"
 // child lifetime scope things with the adapter.
 // ReSharper disable once UnusedMember.Global
 public void ConfigureContainer(AutofacChildLifetimeScopeConfigurationAdapter config)
 {
 }
 // Here's the change for child lifetime scope usage! Register your "root"
 // child lifetime scope things with the adapter.
 public void ConfigureContainer(AutofacChildLifetimeScopeConfigurationAdapter config)
 {
     config.Add(builder => builder.RegisterModule(new AutofacModule()));
 }
 // ConfigureContainer is where you can register things directly
 // with Autofac. This runs after ConfigureServices so the things
 // here will override registrations made in ConfigureServices.
 // Don't build the container; that gets done for you by the factory.
 public void ConfigureContainer(AutofacChildLifetimeScopeConfigurationAdapter config)
 {
     // Register your own things directly with Autofac
 }