public void Configure(IApplicationBuilder app) { AutofacContainer = app.ApplicationServices.GetAutofacRoot(); if (AutofacContainer.IsRegistered <IPrintMessages>()) { app.Use(async(context, next) => { IPrintMessages service = app.ApplicationServices.GetRequiredService <IPrintMessages>(); string newContent = service.Print() + service.Print("SinjulMSBH .. !!!!"); await context.Response.WriteAsync(newContent); }); } }
// 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())); //} //public static MultitenantContainer ConfigureMultitenantContainer(IContainer container) //{ // // This is the MULTITENANT PART. Set up your tenant-specific stuff here. // var strategy = new MyTenantIdentificationStrategy(); // var mtc = new MultitenantContainer(strategy, container); // mtc.ConfigureTenant("a" , cb => cb.RegisterType<TenantDependency>( ).As<IDependency>( )); // return mtc; //} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { // If, for some reason, you need a reference to the built container, you // can use the convenience extension method GetAutofacRoot. //if (!(serviceProvider is AutofacServiceProvider autofacServiceProvider)) // throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ServiceProviderExtensionsResources.WrongProviderType, serviceProvider?.GetType())); //return autofacServiceProvider.LifetimeScope; //AutofacContainer.ChildLifetimeScopeBeginning AutofacContainer = app.ApplicationServices.GetAutofacRoot( ); if (AutofacContainer.IsRegistered <IPrintMessages>( )) { app.Use(async(context, next) => { IPrintMessages service = app.ApplicationServices.GetRequiredService <IPrintMessages>(); string newContent = service.Print() + service.Print(" SinjulMSBH .. !!!!"); await context.Response.WriteAsync(newContent); }); } }