/// <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> /// Will search to find a The http request header in the current http request. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="builder"></param> /// <param name="headerName">The http request header name from where to extract the tenant id. ie: X-Tenant-Id</param> /// <param name="lifetime"></param> /// <returns></returns> /// <remarks>In order to use this strategy ensure that the UseRouting call precedes the UseMultiTenancy middleware</remarks> public static TenantBuilder <T> FromHeader <T>(this TenantBuilder <T> builder, string headerName = Constants.HttpRequestHeaderName, ServiceLifetime lifetime = ServiceLifetime.Transient) where T : Tenant => builder.WithResolutionStrategy((sp) => { var accessor = sp.GetRequiredService <IHttpContextAccessor>(); return(new HeaderResolutionStrategy(accessor, headerName)); }, lifetime);
/// <summary> /// Will search to find the current tenant identifier from the currently running application Host. For example www.indice.gr /// </summary> /// <typeparam name="T"></typeparam> /// <param name="builder"></param> /// <param name="lifetime"></param> /// <returns></returns> public static TenantBuilder <T> FromHost <T>(this TenantBuilder <T> builder, ServiceLifetime lifetime = ServiceLifetime.Transient) where T : Tenant => builder.WithResolutionStrategy <HostResolutionStrategy>(lifetime);