First Commit

This commit is contained in:
Jorge Luis caudillo esparza
2026-05-09 16:36:57 -07:00
parent 96ad4c0d3e
commit d0c284d9c0
131 changed files with 4009 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
namespace ADS.Helpers.MultiTenant.Context;
public interface ITenantContextAccessor
{
TenantContext? Current { get; }
void SetCurrent(TenantContext? context);
}

View File

@@ -0,0 +1,17 @@
using ADS.Helpers.MultiTenant.Abstractions;
using ADS.Helpers.MultiTenant.Context;
namespace ADS.Helpers.MultiTenant.Stores;
public sealed class InMemoryTenantStore : ITenantStore
{
private readonly Dictionary<string, TenantContext> _tenants = new(StringComparer.OrdinalIgnoreCase)
{
["demo"] = new TenantContext { TenantId = "demo", EmpresaId = 172, ClienteId = 1 }
};
public Task<TenantContext?> GetAsync(string tenantKey)
{
_tenants.TryGetValue(tenantKey, out var tenant);
return Task.FromResult<TenantContext?>(tenant);
}
}

View File

@@ -0,0 +1,22 @@
namespace ADS.Helpers.MultiTenant.Context;
public sealed class TenantContext
{
public int EmpresaId { get; set; }
public int ClienteId { get; set; }
public string TenantId { get; set; } = string.Empty;
public string Culture { get; set; } = "es-MX";
public string Theme { get; set; } = string.Empty;
public DatabaseConfig Database { get; set; } = new();
// Settings no tipados (solo si quieres algo rápido para cosas raras)
public Dictionary<string, string> CustomSettings { get; set; } = new();
}
public sealed class DatabaseConfig
{
public string Provider { get; set; } = "SqlServer"; // SqlServer | Postgres
public string ConnectionString { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,12 @@
using System.Threading;
namespace ADS.Helpers.MultiTenant.Context;
public sealed class TenantContextAccessor : ITenantContextAccessor
{
private static readonly AsyncLocal<TenantContext?> _current = new();
public TenantContext? Current => _current.Value;
public void SetCurrent(TenantContext? context) => _current.Value = context;
}