* Refactor: Update namespaces and add TenantExtensions Updated namespaces throughout the project to improve clarity and consistency by moving from 'Common' to appropriate modules. Added TenantExtensions class to simplify fetching connection strings for tenants. * Implement multitenant DB connection strings Redesign tenant-specific classes to support multitenancy more effectively. Introduce `MultitenantBackgroundService` and `MultitenantHostedService` for handling tasks per tenant. * Refactor constructors and remove redundant code Simplified the constructor parameters for `MultitenantBackgroundService` and `List` class. Removed the unused parameter in `MultitenantBackgroundService` and redundant folder inclusion in the project file. Updated the method calls to use direct parameters in `List` class. * Remove unused import in ActivityDescriptors Endpoint The Elsa.Common.Multitenancy import was removed as it is unused in the List/Endpoint.cs file. Removing unused imports helps to improve code readability and maintainability. This change does not affect functionality.
59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Concurrent;
|
|
using Elsa.Extensions;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Elsa.Http.Services;
|
|
|
|
/// <inheritdoc />
|
|
public class RouteTable(IMemoryCache cache, ILogger<RouteTable> logger) : IRouteTable
|
|
{
|
|
private static readonly object Key = new();
|
|
|
|
private ConcurrentDictionary<string, HttpRouteData> Routes => cache.GetOrCreate(Key, _ => new ConcurrentDictionary<string, HttpRouteData>())!;
|
|
|
|
/// <inheritdoc />
|
|
public void Add(string route)
|
|
{
|
|
Add(new HttpRouteData(route));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Add(HttpRouteData httpRouteData)
|
|
{
|
|
var route = httpRouteData.Route;
|
|
if (route.Contains("//"))
|
|
{
|
|
logger.LogWarning("Path cannot contain double slashes. Ignoring path: {Path}", route);
|
|
return;
|
|
}
|
|
|
|
var normalizedRoute = route.NormalizeRoute();
|
|
Routes.TryAdd(normalizedRoute, httpRouteData);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Remove(string route)
|
|
{
|
|
var normalizedRoute = route.NormalizeRoute();
|
|
Routes.TryRemove(normalizedRoute, out _);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void AddRange(IEnumerable<string> routes)
|
|
{
|
|
foreach (var route in routes) Add(route);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void RemoveRange(IEnumerable<string> routes)
|
|
{
|
|
foreach (var route in routes) Remove(route);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IEnumerator<HttpRouteData> GetEnumerator() => Routes.Values.GetEnumerator();
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
} |