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,8 @@
using System.Data;
namespace ADS.Helpers.MultiTenant.Data;
public interface IDbConnectionFactory
{
IDbConnection Create();
}

View File

@@ -0,0 +1,25 @@
using System.Data;
using ADS.Helpers.MultiTenant.InternalRouting;
using Microsoft.AspNetCore.Http;
using Microsoft.Data.SqlClient;
namespace ADS.Helpers.MultiTenant.Data;
public sealed class TenantDbConnectionFactory : IDbConnectionFactory
{
private readonly IHttpContextAccessor _http;
public TenantDbConnectionFactory(IHttpContextAccessor http) => _http = http;
public IDbConnection Create()
{
var ctx = _http.HttpContext ?? throw new InvalidOperationException("HTTP_CONTEXT_NOT_AVAILABLE");
if (!ctx.Items.TryGetValue(InternalTenantDbHeaders.ItemConn, out var csObj) ||
csObj is not string cs ||
string.IsNullOrWhiteSpace(cs))
throw new InvalidOperationException("INTERNAL_CONN_MISSING");
return new SqlConnection(cs);
}
}