optimizing tenant resolution and routing
This commit is contained in:
@ -8,9 +8,10 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Oqtane.Extensions;
|
||||
using Oqtane.Infrastructure;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Migrations.Framework;
|
||||
using Oqtane.Repository.Databases.Interfaces;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
|
||||
// ReSharper disable BuiltInTypeReferenceStyleForMemberAccess
|
||||
@ -20,26 +21,27 @@ namespace Oqtane.Repository
|
||||
public class DBContextBase : IdentityUserContext<IdentityUser>
|
||||
{
|
||||
private readonly ITenantResolver _tenantResolver;
|
||||
private readonly ITenantManager _tenantManager;
|
||||
private readonly IHttpContextAccessor _accessor;
|
||||
private readonly IConfiguration _configuration;
|
||||
private string _connectionString;
|
||||
private string _databaseType;
|
||||
|
||||
public DBContextBase(ITenantResolver tenantResolver, IHttpContextAccessor httpContextAccessor)
|
||||
public DBContextBase(ITenantManager tenantManager, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_connectionString = String.Empty;
|
||||
_tenantResolver = tenantResolver;
|
||||
_tenantManager = tenantManager;
|
||||
_accessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public DBContextBase(IDbConfig dbConfig, ITenantResolver tenantResolver)
|
||||
public DBContextBase(IDbConfig dbConfig, ITenantManager tenantManager)
|
||||
{
|
||||
_accessor = dbConfig.Accessor;
|
||||
_configuration = dbConfig.Configuration;
|
||||
_connectionString = dbConfig.ConnectionString;
|
||||
_databaseType = dbConfig.DatabaseType;
|
||||
Databases = dbConfig.Databases;
|
||||
_tenantResolver = tenantResolver;
|
||||
_tenantManager = tenantManager;
|
||||
}
|
||||
|
||||
public IEnumerable<IOqtaneDatabase> Databases { get; }
|
||||
@ -48,9 +50,18 @@ namespace Oqtane.Repository
|
||||
{
|
||||
optionsBuilder.ReplaceService<IMigrationsAssembly, MultiDatabaseMigrationsAssembly>();
|
||||
|
||||
if (string.IsNullOrEmpty(_connectionString) && _tenantResolver != null)
|
||||
if (string.IsNullOrEmpty(_connectionString))
|
||||
{
|
||||
var tenant = _tenantResolver.GetTenant();
|
||||
|
||||
Tenant tenant;
|
||||
if (_tenantResolver != null)
|
||||
{
|
||||
tenant = _tenantResolver.GetTenant();
|
||||
}
|
||||
else
|
||||
{
|
||||
tenant = _tenantManager.GetTenant();
|
||||
}
|
||||
|
||||
if (tenant != null)
|
||||
{
|
||||
@ -103,5 +114,25 @@ namespace Oqtane.Repository
|
||||
|
||||
return base.SaveChanges();
|
||||
}
|
||||
|
||||
[Obsolete("This constructor is obsolete. Use DBContextBase(ITenantManager tenantManager, IHttpContextAccessor httpContextAccessor) instead.", false)]
|
||||
public DBContextBase(ITenantResolver tenantResolver, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_connectionString = String.Empty;
|
||||
_tenantResolver = tenantResolver;
|
||||
_accessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
[Obsolete("This constructor is obsolete. Use DBContextBase(IDbConfig dbConfig, ITenantManager tenantManager) instead.", false)]
|
||||
public DBContextBase(IDbConfig dbConfig, ITenantResolver tenantResolver)
|
||||
{
|
||||
_accessor = dbConfig.Accessor;
|
||||
_configuration = dbConfig.Configuration;
|
||||
_connectionString = dbConfig.ConnectionString;
|
||||
_databaseType = dbConfig.DatabaseType;
|
||||
Databases = dbConfig.Databases;
|
||||
_tenantResolver = tenantResolver;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user