40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
|
|
using System;
|
||
|
|
using APT.Infrastructure.Api;
|
||
|
|
using Microsoft.Extensions.Configuration;
|
||
|
|
|
||
|
|
namespace APT.Infrastructure.EF
|
||
|
|
{
|
||
|
|
public class NamedConnectionGenerator : IConnectionGenerator
|
||
|
|
{
|
||
|
|
private readonly IConfiguration configuration;
|
||
|
|
public string TenantKey => "unknow";
|
||
|
|
|
||
|
|
public NamedConnectionGenerator(IConfiguration configuration)
|
||
|
|
{
|
||
|
|
this.configuration = configuration;
|
||
|
|
}
|
||
|
|
|
||
|
|
public string GetConnection(TenantOption option, TenantInfo tenantInfo)
|
||
|
|
{
|
||
|
|
string connectionString = null;
|
||
|
|
switch (option.ConnectionType)
|
||
|
|
{
|
||
|
|
case ConnectionResolverType.ByDatabase:
|
||
|
|
connectionString = configuration.GetConnectionString($"{option.ConnectionPrefix}{tenantInfo.Name}");
|
||
|
|
break;
|
||
|
|
case ConnectionResolverType.ByTable:
|
||
|
|
case ConnectionResolverType.BySchema:
|
||
|
|
connectionString = configuration.GetConnectionString(option.ConnectionName);
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
return connectionString;
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool MatchTenantKey(string tenantKey)
|
||
|
|
{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|