public IServiceProvider ConfigureServices(IServiceCollection services) { services .AddAutofacMultitenantRequestServices(() => ApplicationContainer) .AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var builder = new ContainerBuilder(); builder.Populate(services); builder.RegisterType <Dependency>() .As <IDependency>() .WithProperty("Id", "base") .InstancePerLifetimeScope(); var container = builder.Build(); var strategy = new QueryStringTenantIdentificationStrategy(container.Resolve <IHttpContextAccessor>(), container.Resolve <ILogger <QueryStringTenantIdentificationStrategy> >()); var mtc = new MultitenantContainer(strategy, container); mtc.ConfigureTenant( "a", cb => cb .RegisterType <Dependency>() .As <IDependency>() .WithProperty("Id", "a") .InstancePerLifetimeScope()); mtc.ConfigureTenant( "b", cb => cb .RegisterType <Dependency>() .As <IDependency>() .WithProperty("Id", "b") .InstancePerLifetimeScope()); ApplicationContainer = mtc; return(new AutofacServiceProvider(mtc)); }
public static MultitenantContainer ConfigureMultitenantContainer(IContainer container) { var strategy = new QueryStringTenantIdentificationStrategy( container.Resolve <IHttpContextAccessor>(), container.Resolve <ILogger <QueryStringTenantIdentificationStrategy> >()); var multitenantContainer = new MultitenantContainer(strategy, container); multitenantContainer.ConfigureTenant( "a", cb => cb .RegisterType <Dependency>() .As <IDependency>() .WithProperty("Id", "a") .InstancePerLifetimeScope()); multitenantContainer.ConfigureTenant( "b", cb => cb .RegisterType <Dependency>() .As <IDependency>() .WithProperty("Id", "b") .InstancePerLifetimeScope()); return(multitenantContainer); }
public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); var builder = new ContainerBuilder(); builder.Populate(services); builder.Register(ctx => new Dependency { Id = "base" }).As <IDependency>(); var container = builder.Build(); var strategy = new QueryStringTenantIdentificationStrategy(container.Resolve <IHttpContextAccessor>()); var mtc = new MultitenantContainer(strategy, container); mtc.ConfigureTenant("a", cb => cb.Register(ctx => new Dependency { Id = "a" }).As <IDependency>()); mtc.ConfigureTenant("b", cb => cb.Register(ctx => new Dependency { Id = "b" }).As <IDependency>()); Startup.ApplicationContainer = mtc; return(new AutofacServiceProvider(mtc)); }