/// <summary> /// Add the services (application specific tenant class) /// </summary> /// <param name="services"></param> public static IServiceCollection AddMultitenancy <TTenant, TTenantStore, TResolutionStrategy>(this IServiceCollection services) where TTenant : class, ITenant where TTenantStore : ITenantStore <TTenant> where TResolutionStrategy : ITenantResolutionStrategy { services.AddScoped <ITenantAccessor <TTenant>, TenantAccessor <TTenant> >(); var tenantBuilder = new TenantBuilder <TTenant>(services); tenantBuilder.WithStore <TTenantStore>(); tenantBuilder.WithResolutionStrategy <TResolutionStrategy>(); return(services); }
/// <summary> /// Register the tenant store implementation In memory /// </summary> /// <param name="builder">The builder</param> /// <param name="tenants">Available tenants</param> /// <param name="lifetime"></param> /// <returns></returns> public static TenantBuilder <T> WithInMemoryStore <T>(this TenantBuilder <T> builder, IEnumerable <T> tenants, ServiceLifetime lifetime = ServiceLifetime.Transient) where T : Tenant => builder.WithStore((sp) => new InMemoryTenantStore <T>(tenants), lifetime);