feat: 完成多租户saas框架搭建
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
using Volo.Abp;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Volo.Abp.ObjectMapping;
|
||||
|
||||
namespace Yi.Framework.TenantManagement.Domain
|
||||
{
|
||||
@@ -96,21 +94,23 @@ namespace Yi.Framework.TenantManagement.Domain
|
||||
private ConnectionStrings? MaptoString(string tenantConnectionString)
|
||||
{
|
||||
|
||||
tenantConnectionString = tenantConnectionString.TrimEnd(';');
|
||||
var strSpiteds = tenantConnectionString.Split(";");
|
||||
if (strSpiteds.Count() == 0)
|
||||
{
|
||||
return null;
|
||||
//tenantConnectionString = tenantConnectionString.TrimEnd(';');
|
||||
//var strSpiteds = tenantConnectionString.Split(";");
|
||||
//if (strSpiteds.Count() == 0)
|
||||
//{
|
||||
// return null;
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
var connectionStrings = new ConnectionStrings();
|
||||
foreach (string strSpited in strSpiteds)
|
||||
{
|
||||
var key = strSpited.Split('=')[0];
|
||||
var value = strSpited.Split('=')[1];
|
||||
connectionStrings[key] = value;
|
||||
}
|
||||
//foreach (string strSpited in strSpiteds)
|
||||
//{
|
||||
// var key = strSpited.Split('=')[0];
|
||||
// var value = strSpited.Split('=')[1];
|
||||
// connectionStrings[key] = value;
|
||||
//}
|
||||
connectionStrings["test"] = tenantConnectionString;
|
||||
|
||||
return connectionStrings;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,12 @@ using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Domain.Entities.Auditing;
|
||||
using Volo.Abp.TenantManagement;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.TenantManagement.Domain
|
||||
{
|
||||
[SugarTable("Tenant")]
|
||||
[MasterTenant]
|
||||
public class TenantAggregateRoot : FullAuditedAggregateRoot<Guid>, IHasEntityVersion
|
||||
{
|
||||
public TenantAggregateRoot()
|
||||
@@ -21,8 +23,8 @@ namespace Yi.Framework.TenantManagement.Domain
|
||||
SetName(name);
|
||||
}
|
||||
|
||||
[SugarColumn(IsPrimaryKey =true)]
|
||||
public override Guid Id { get ; protected set; }
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public override Guid Id { get; protected set; }
|
||||
public virtual string Name { get; protected set; }
|
||||
public int EntityVersion { get; protected set; }
|
||||
|
||||
@@ -30,9 +32,9 @@ namespace Yi.Framework.TenantManagement.Domain
|
||||
|
||||
public DbType DbType { get; protected set; }
|
||||
|
||||
[SugarColumn(IsIgnore=true)]
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public override ExtraPropertyDictionary ExtraProperties { get => base.ExtraProperties; protected set => base.ExtraProperties = value; }
|
||||
public virtual void SetConnectionString(DbType dbType,string connectionString)
|
||||
public virtual void SetConnectionString(DbType dbType, string connectionString)
|
||||
{
|
||||
DbType = dbType;
|
||||
TenantConnectionString = connectionString;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.TenantManagement.Domain
|
||||
{
|
||||
public static class TenantManagementExtensions
|
||||
{
|
||||
public static IDisposable ChangeMaster(this ICurrentTenant currentTenant)
|
||||
{
|
||||
return currentTenant.Change(null, DbConnOptions.MasterTenantDbDefaultName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="8.0.0" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Domain.Shared" Version="8.0.0" />
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Domain.Shared" Version="8.0.0" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.TenantManagement.Domain.Shared
|
||||
{
|
||||
public class TenantConst
|
||||
{
|
||||
public static string TenantDbDefaultName = "Master";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.TenantManagement.Domain.Shared" Version="8.0.0" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,11 @@
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.TenantManagement;
|
||||
|
||||
namespace YiFrameworkTenantManagementDomain.Shared
|
||||
{
|
||||
[DependsOn(typeof(AbpTenantManagementDomainSharedModule))]
|
||||
public class YiFrameworkTenantManagementDomainSharedModule : AbpModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user