| | | 1 | | using Elsa.Common.Multitenancy; |
| | | 2 | | using Elsa.Features.Abstractions; |
| | | 3 | | using Elsa.Features.Attributes; |
| | | 4 | | using Elsa.Features.Services; |
| | | 5 | | using Elsa.Http.Features; |
| | | 6 | | using Elsa.Tenants.AspNetCore.Options; |
| | | 7 | | using Elsa.Tenants.AspNetCore.Services; |
| | | 8 | | using Elsa.Tenants.Features; |
| | | 9 | | using Microsoft.Extensions.DependencyInjection; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Tenants.AspNetCore.Features; |
| | | 12 | | |
| | | 13 | | [DependencyOf(typeof(HttpFeature))] |
| | | 14 | | [DependencyOf(typeof(TenantsFeature))] |
| | 0 | 15 | | public class MultitenantHttpRoutingFeature(IModule module) : FeatureBase(module) |
| | | 16 | | { |
| | 0 | 17 | | private Action<MultitenancyHttpOptions> _configureMultitenancyHttpOptions = _ => { }; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Configures the MultitenantHttpRoutingFeature to use a specific tenant header name. |
| | | 21 | | /// </summary> |
| | | 22 | | /// <param name="headerName">The name of the HTTP header used to identify the tenant.</param> |
| | | 23 | | /// <returns>The current instance of <see cref="MultitenantHttpRoutingFeature"/> for fluent configuration.</returns> |
| | 0 | 24 | | public MultitenantHttpRoutingFeature WithTenantHeader(string headerName) => WithMultitenancyHttpOptions(options => o |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Configures the MultitenantHttpRoutingFeature with custom multitenancy HTTP options. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="configure">The action to configure <see cref="MultitenancyHttpOptions"/>.</param> |
| | | 30 | | /// <returns>The current instance of <see cref="MultitenantHttpRoutingFeature"/> for fluent configuration.</returns> |
| | | 31 | | public MultitenantHttpRoutingFeature WithMultitenancyHttpOptions(Action<MultitenancyHttpOptions> configure) |
| | | 32 | | { |
| | 0 | 33 | | _configureMultitenancyHttpOptions = configure; |
| | 0 | 34 | | return this; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public override void Configure() |
| | | 38 | | { |
| | 0 | 39 | | Module.Configure<HttpFeature>(feature => |
| | 0 | 40 | | { |
| | 0 | 41 | | feature.WithHttpEndpointRoutesProvider<TenantPrefixHttpEndpointRoutesProvider>(); |
| | 0 | 42 | | feature.WithHttpEndpointBasePathProvider<TenantPrefixHttpEndpointBasePathProvider>(); |
| | 0 | 43 | | }); |
| | 0 | 44 | | } |
| | | 45 | | |
| | | 46 | | public override void Apply() |
| | | 47 | | { |
| | | 48 | | // Multitenancy HTTP options. |
| | 0 | 49 | | Services.Configure(_configureMultitenancyHttpOptions); |
| | | 50 | | |
| | | 51 | | // Tenant resolvers. |
| | 0 | 52 | | Services |
| | 0 | 53 | | .AddScoped<ITenantResolver, RoutePrefixTenantResolver>() |
| | 0 | 54 | | .AddScoped<ITenantResolver, HeaderTenantResolver>() |
| | 0 | 55 | | .AddScoped<ITenantResolver, HostTenantResolver>() |
| | 0 | 56 | | .AddScoped<TenantPrefixHttpEndpointRoutesProvider>(); |
| | 0 | 57 | | } |
| | | 58 | | } |