| | | 1 | | using CShells.Features; |
| | | 2 | | using Elsa.Common.Multitenancy; |
| | | 3 | | using Elsa.PackageManifest.Generator.Hints; |
| | | 4 | | using Elsa.Tenants.AspNetCore.Options; |
| | | 5 | | using Elsa.Tenants.AspNetCore.Services; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | using Microsoft.Extensions.DependencyInjection; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Tenants.AspNetCore.ShellFeatures; |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Provides multi-tenant HTTP routing features. |
| | | 13 | | /// </summary> |
| | | 14 | | [ShellFeature( |
| | | 15 | | DisplayName = "Multi-tenant HTTP Routing", |
| | | 16 | | Description = "Provides multi-tenant HTTP routing capabilities for workflows")] |
| | | 17 | | [UsedImplicitly] |
| | | 18 | | public class MultitenantHttpRoutingFeature : IShellFeature |
| | | 19 | | { |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets or sets the tenant header name. |
| | | 22 | | /// </summary> |
| | | 23 | | [ManifestSetting( |
| | | 24 | | DisplayName = "Tenant Header Name", |
| | | 25 | | Description = "HTTP header used to resolve the current tenant.", |
| | | 26 | | Category = "Routing", |
| | | 27 | | DefaultValue = "X-Tenant-Id", |
| | | 28 | | RestartRequired = true)] |
| | 0 | 29 | | public string TenantHeaderName { get; set; } = "X-Tenant-Id"; |
| | | 30 | | |
| | | 31 | | public void ConfigureServices(IServiceCollection services) |
| | | 32 | | { |
| | | 33 | | // Multitenancy HTTP options. |
| | 0 | 34 | | services.Configure<MultitenancyHttpOptions>(options => |
| | 0 | 35 | | { |
| | 0 | 36 | | options.TenantHeaderName = TenantHeaderName; |
| | 0 | 37 | | }); |
| | | 38 | | |
| | | 39 | | // Tenant resolvers. |
| | 0 | 40 | | services |
| | 0 | 41 | | .AddScoped<ITenantResolver, RoutePrefixTenantResolver>() |
| | 0 | 42 | | .AddScoped<ITenantResolver, HeaderTenantResolver>() |
| | 0 | 43 | | .AddScoped<ITenantResolver, HostTenantResolver>() |
| | 0 | 44 | | .AddScoped<TenantPrefixHttpEndpointRoutesProvider>(); |
| | 0 | 45 | | } |
| | | 46 | | } |