| | | 1 | | using Elsa.Common.Features; |
| | | 2 | | using Elsa.Common.Multitenancy; |
| | | 3 | | using Elsa.Features.Abstractions; |
| | | 4 | | using Elsa.Features.Attributes; |
| | | 5 | | using Elsa.Features.Services; |
| | | 6 | | using Elsa.Tenants.Mediator.Tasks; |
| | | 7 | | using Elsa.Tenants.Options; |
| | | 8 | | using Elsa.Tenants.Providers; |
| | | 9 | | using Microsoft.Extensions.DependencyInjection; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Tenants.Features; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Configures multi-tenancy features. |
| | | 15 | | /// </summary> |
| | | 16 | | [DependencyOf(typeof(MultitenancyFeature))] |
| | 0 | 17 | | public class TenantsFeature(IModule serviceConfiguration) : FeatureBase(serviceConfiguration) |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Configures the Tenants options. |
| | | 21 | | /// </summary> |
| | 0 | 22 | | private Action<MultitenancyOptions> MultitenancyOptions { get; set; } = _ => { }; |
| | | 23 | | |
| | 0 | 24 | | private Action<TenantsOptions> TenantsOptions { get; set; } = _ => { }; |
| | | 25 | | |
| | | 26 | | public TenantsFeature ConfigureMultitenancy(Action<MultitenancyOptions> configure) |
| | | 27 | | { |
| | 0 | 28 | | Services.Configure(configure); |
| | 0 | 29 | | return this; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | public TenantsFeature ConfigureTenants(Action<TenantsOptions> configure) |
| | | 33 | | { |
| | 0 | 34 | | Services.Configure(configure); |
| | 0 | 35 | | return this; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | public void UseConfigurationBasedTenantsProvider(Action<TenantsOptions> configure) |
| | | 39 | | { |
| | 0 | 40 | | ConfigureTenants(configure); |
| | 0 | 41 | | Module.Configure<MultitenancyFeature>(feature => feature.UseTenantsProvider<ConfigurationTenantsProvider>()); |
| | 0 | 42 | | } |
| | | 43 | | |
| | | 44 | | public void UseStoreBasedTenantsProvider() |
| | | 45 | | { |
| | 0 | 46 | | Module.Configure<MultitenancyFeature>(feature => feature.UseTenantsProvider<StoreTenantsProvider>()); |
| | 0 | 47 | | } |
| | | 48 | | |
| | | 49 | | public override void ConfigureHostedServices() |
| | | 50 | | { |
| | 0 | 51 | | Module.ConfigureHostedService<SetupMediatorPipelines>(); |
| | 0 | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <inheritdoc /> |
| | | 55 | | public override void Apply() |
| | | 56 | | { |
| | 0 | 57 | | Services.Configure(MultitenancyOptions); |
| | | 58 | | |
| | 0 | 59 | | Services |
| | 0 | 60 | | .AddScoped<ITenantResolverPipelineInvoker, DefaultTenantResolverPipelineInvoker>() |
| | 0 | 61 | | .AddScoped<ITenantResolver, DefaultTenantResolver>(); |
| | 0 | 62 | | } |
| | | 63 | | } |