AutofacChildLifetimeScopeConfigurationAdapter

We found 10 examples in language CSharp for this search. You will see 22 fragments of code.

Other methods

        [Fact]
        public void AddMultipleConfigurationContainsConfigurations()
        {
            var adapter = new AutofacChildLifetimeScopeConfigurationAdapter();
            adapter.Add(builder => { });
            adapter.Add(builder => { });

            Assert.Equal(2, adapter.ConfigurationActions.Count);
        }

        [Fact]
        public void AddNullConfigurationThrows()
            => Assert.Throws<ArgumentNullException>(() => new AutofacChildLifetimeScopeConfigurationAdapter().Add(null));

        [Fact]
        public void AddMultipleConfigurationContainsConfigurations()
        {
            var adapter = new AutofacChildLifetimeScopeConfigurationAdapter();
            adapter.Add(builder => { });
            adapter.Add(builder => { });

            Assert.Equal(2, adapter.ConfigurationActions.Count);
        }

        [Fact]
        public void AddNullConfigurationThrows()
            => Assert.Throws<ArgumentNullException>(() => new AutofacChildLifetimeScopeConfigurationAdapter().Add(null));


        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }

        public void ConfigureContainer(AutofacChildLifetimeScopeConfigurationAdapter adapter)
        {

        }

        /// <summary>
        /// Configures the application.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="lifetime"></param>
        public void Configure(IApplicationBuilder app)
        {
            app.Use(async (ctx, next) =>
            {
                var s = ctx.RequestServices.GetRequiredService<ILifetimeScope>();
                var l = ctx.RequestServices.GetRequiredService<ILogger>();
                l.LogInformation("request");
                await next();
            });
        }


        public void ConfigureServices(IServiceCollection services)
        {

        }

        public void ConfigureContainer(AutofacChildLifetimeScopeConfigurationAdapter builder)
        {

        }

        /// <summary>
        /// Configures the application.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="lifetime"></param>
        public void Configure(IApplicationBuilder app)
        {
            app.Use(async (ctx, next) =>
            {
                var s = ctx.RequestServices.GetRequiredService<ILifetimeScope>();
                var l = ctx.RequestServices.GetRequiredService<ILogger>();
                l.LogInformation("request");
                await next();
            });
        }


        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.AddCloudFoundryServices(Configuration);
            services.AddMediatRServices();
            services.AddApiVersioningServices(Configuration);
            services.AddSwaggerServices();
            services.AddControllers();
            services.AddValidatorsFromAssemblyContaining<Startup>();
        }


        // 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
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration, IApiVersionDescriptionProvider provider)
        {
            if (env.IsDevelopment())
                app.UseDeveloperExceptionPage();
            else
                app.UseHsts();
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.ConfigureExceptionMiddleware();
            app.ConfigureSwagger(provider);
            app.UseRouting();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            app.ConfigureCloudFoundryServices(configuration);
        }


        /// <summary>
        /// Adds a configuration action that will be executed when the child <see cref="ILifetimeScope"/> is created.
        /// </summary>
        /// <param name="configurationAction">Action on a <see cref="ContainerBuilder"/> that adds component registrations to the container.</param>
        /// <exception cref="ArgumentNullException">Throws when the passed configuration-action is null.</exception>
        public void Add(Action<ContainerBuilder> configurationAction)
        {
            if (configurationAction == null) throw new ArgumentNullException(nameof(configurationAction));

            _configurationActions.Add(configurationAction);
        }


        /// <summary>
        /// Adds a configuration action that will be executed when the child <see cref="ILifetimeScope"/> is created.
        /// </summary>
        /// <param name="configurationAction">Action on a <see cref="ContainerBuilder"/> that adds component registrations to the container.</param>
        /// <exception cref="ArgumentNullException">Throws when the passed configuration-action is null.</exception>
        public void Add(Action<ContainerBuilder> configurationAction)
        {
            if (configurationAction == null) throw new ArgumentNullException(nameof(configurationAction));

            _configurationActions.Add(configurationAction);
        }



        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages()
                .WithRazorPagesRoot(Defaults.RazorPagesRoot)
                
                .AddJsonOptions(
                    options => options.JsonSerializerOptions.IgnoreNullValues = true
                );
        }

        // 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)
        {
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
                app.UseDeveloperExceptionPage();
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseStatusCodePages();
            app.UseHttpsRedirection();
            app.UseStaticFiles(new StaticFileOptions
            {
                RequestPath = "",
                FileProvider =
                    new PhysicalFileProvider(Path.Combine(Environment.CurrentDirectory, Defaults.PresentationDirectory))
            });
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
            });
        }

        private static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(
                    new AutofacChildLifetimeScopeServiceProviderFactory(
                        Container.BeginLifetimeScope("root-one")))
                .ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<AspNetCoreStartup>());

        public static void StartAsync(string[] args) => CreateHostBuilder(args).Build().RunAsync();


        /// <summary>
        /// Adds a configuration action that will be executed when the child <see cref="ILifetimeScope"/> is created.
        /// </summary>
        /// <param name="configurationAction">Action on a <see cref="ContainerBuilder"/> that adds component registrations to the container.</param>
        /// <exception cref="ArgumentNullException">Throws when the passed configuration-action is null.</exception>
        public void Add(Action<ContainerBuilder> configurationAction)
        {
            if (configurationAction == null) throw new ArgumentNullException(nameof(configurationAction));

            _configurationActions.Add(configurationAction);
        }


        /// <summary>
        /// Adds a configuration action that will be executed when the child <see cref="ILifetimeScope"/> is created.
        /// </summary>
        /// <param name="configurationAction">Action on a <see cref="ContainerBuilder"/> that adds component registrations to the container.</param>
        /// <exception cref="ArgumentNullException">Throws when the passed configuration-action is null.</exception>
        public void Add(Action<ContainerBuilder> configurationAction)
        {
            if (configurationAction == null) throw new ArgumentNullException(nameof(configurationAction));

            _configurationActions.Add(configurationAction);
        }

Autofac.Extensions.DependencyInjection.AutofacChildLifetimeScopeConfigurationAdapter : Object

Constructors :

public AutofacChildLifetimeScopeConfigurationAdapter()

Methods :

public Void Add(Action<ContainerBuilder> configurationAction = )
public IReadOnlyList<Action<ContainerBuilder>> get_ConfigurationActions()
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()