From 09f11ae959ea7e7abfecef04dfedade49b7eb1ac Mon Sep 17 00:00:00 2001 From: 2017875139 <2017875139@qq.com> Date: Mon, 14 Mar 2022 08:16:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...e.cs => TenantManagementMappingProfile.cs} | 4 +- .../TenantAggregation/ITenantManager.cs | 8 --- .../DDD/Domain/TenantAggregation/Tenant.cs | 56 ------------------- .../TenantConnectionString.cs | 36 ------------ .../Domain/TenantAggregation/TenantManager.cs | 44 --------------- sample/Tenant.Api/TenantMappingProfile.cs | 13 ----- 6 files changed, 2 insertions(+), 159 deletions(-) rename sample/Tenant.Api/DDD/Contracts/{TenantManagementDomainMappingProfile.cs => TenantManagementMappingProfile.cs} (76%) delete mode 100644 sample/Tenant.Api/DDD/Domain/TenantAggregation/ITenantManager.cs delete mode 100644 sample/Tenant.Api/DDD/Domain/TenantAggregation/Tenant.cs delete mode 100644 sample/Tenant.Api/DDD/Domain/TenantAggregation/TenantConnectionString.cs delete mode 100644 sample/Tenant.Api/DDD/Domain/TenantAggregation/TenantManager.cs delete mode 100644 sample/Tenant.Api/TenantMappingProfile.cs diff --git a/sample/Tenant.Api/DDD/Contracts/TenantManagementDomainMappingProfile.cs b/sample/Tenant.Api/DDD/Contracts/TenantManagementMappingProfile.cs similarity index 76% rename from sample/Tenant.Api/DDD/Contracts/TenantManagementDomainMappingProfile.cs rename to sample/Tenant.Api/DDD/Contracts/TenantManagementMappingProfile.cs index 8fee9b3..a7d3ea8 100644 --- a/sample/Tenant.Api/DDD/Contracts/TenantManagementDomainMappingProfile.cs +++ b/sample/Tenant.Api/DDD/Contracts/TenantManagementMappingProfile.cs @@ -5,9 +5,9 @@ using TenantManagement.Api.DDD.Domain.Entites; namespace TenantManagement.Api.DDD.Contracts; -public class TenantManagementDomainMappingProfile : Profile +public class TenantManagementMappingProfile : Profile { - public TenantManagementDomainMappingProfile() + public TenantManagementMappingProfile() { CreateMap(); CreateMap(); diff --git a/sample/Tenant.Api/DDD/Domain/TenantAggregation/ITenantManager.cs b/sample/Tenant.Api/DDD/Domain/TenantAggregation/ITenantManager.cs deleted file mode 100644 index fd87f75..0000000 --- a/sample/Tenant.Api/DDD/Domain/TenantAggregation/ITenantManager.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Tenant.Api.DDD.Domain.TenantAggregate; - -public interface ITenantManager -{ - Task CreateAsync(string name); - - Task ChangeNameAsync(Tenant tenant, string name); -} diff --git a/sample/Tenant.Api/DDD/Domain/TenantAggregation/Tenant.cs b/sample/Tenant.Api/DDD/Domain/TenantAggregation/Tenant.cs deleted file mode 100644 index 4e72417..0000000 --- a/sample/Tenant.Api/DDD/Domain/TenantAggregation/Tenant.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Easy; -using Easy.DDD.Domain.Entities; -using Tenant.Api.DDD.Domain.Consts; - -namespace Tenant.Api.DDD.Domain.TenantAggregation; - -public class Tenant : AggregateRoot -{ - public virtual string Name { get; protected set; } - - public virtual List ConnectionStrings { get; protected set; } - - protected Tenant() - { - - } - - protected internal Tenant(Guid id, string name) - : base(id) - { - SetName(name); - - ConnectionStrings = new List(); - } - - - public virtual void SetConnectionString(string name, string connectionString) - { - var tenantConnectionString = ConnectionStrings.FirstOrDefault(x => x.Name == name); - - if (tenantConnectionString != null) - { - tenantConnectionString.SetValue(connectionString); - } - else - { - ConnectionStrings.Add(new TenantConnectionString(Id, name, connectionString)); - } - } - - - public virtual void RemoveConnectionString(string name) - { - var tenantConnectionString = ConnectionStrings.FirstOrDefault(x => x.Name == name); - - if (tenantConnectionString != null) - { - ConnectionStrings.Remove(tenantConnectionString); - } - } - - protected internal virtual void SetName(string name) - { - Name = Check.NotNullOrWhiteSpace(name, nameof(name), TenantConsts.MaxNameLength); - } -} diff --git a/sample/Tenant.Api/DDD/Domain/TenantAggregation/TenantConnectionString.cs b/sample/Tenant.Api/DDD/Domain/TenantAggregation/TenantConnectionString.cs deleted file mode 100644 index 9eeea0d..0000000 --- a/sample/Tenant.Api/DDD/Domain/TenantAggregation/TenantConnectionString.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Easy; -using Easy.DDD.Domain.Entities; -using Tenant.Api.DDD.Domain.Consts; - -namespace Tenant.Api.DDD.Domain.TenantAggregation; - -public class TenantConnectionString : Entity -{ - public virtual Guid TenantId { get; protected set; } - - public virtual string Name { get; protected set; } - - public virtual string Value { get; protected set; } - - protected TenantConnectionString() - { - - } - - public TenantConnectionString(Guid tenantId, string name, string value) - { - TenantId = tenantId; - Name = Check.NotNullOrWhiteSpace(name, nameof(name), TenantConnectionStringConsts.MaxNameLength); - SetValue(value); - } - - public virtual void SetValue(string value) - { - Value = Check.NotNullOrWhiteSpace(value, nameof(value), TenantConnectionStringConsts.MaxValueLength); - } - - public override object[] GetKeys() - { - return new object[] { TenantId, Name }; - } -} diff --git a/sample/Tenant.Api/DDD/Domain/TenantAggregation/TenantManager.cs b/sample/Tenant.Api/DDD/Domain/TenantAggregation/TenantManager.cs deleted file mode 100644 index 9af193b..0000000 --- a/sample/Tenant.Api/DDD/Domain/TenantAggregation/TenantManager.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Easy; -using Easy.DDD.Domain.Repositories; -using Easy.Guids; -using Microsoft.EntityFrameworkCore; - -namespace Tenant.Api.DDD.Domain.TenantAggregation; - -public class TenantManager -{ - public IRepository TenantRepository { get; } - protected IGuidGenerator GuidGenerator { get; } - public TenantManager(IRepository tenantRepository) - { - TenantRepository = tenantRepository; - } - public virtual async Task CreateAsync(string name) - { - Check.NotNull(name, nameof(name)); - - await ValidateNameAsync(name); - return new Tenant(GuidGenerator.Create(), name); - } - - public virtual async Task ChangeNameAsync(Tenant tenant, string name) - { - Check.NotNull(tenant, nameof(tenant)); - Check.NotNull(name, nameof(name)); - - await ValidateNameAsync(name, tenant.Id); - tenant.SetName(name); - } - - protected virtual async Task ValidateNameAsync(string name, Guid? expectedId = null) - { - var tenant = await TenantRepository - .Where(o => o.Name == name) - .Include(x => x.ConnectionStrings) - .OrderBy(t => t.Id) - .FirstOrDefaultAsync(); - - When.Is(tenant != null && tenant.Id != expectedId, "重复的租户名称: " + name); - - } -} diff --git a/sample/Tenant.Api/TenantMappingProfile.cs b/sample/Tenant.Api/TenantMappingProfile.cs deleted file mode 100644 index e0a4d8d..0000000 --- a/sample/Tenant.Api/TenantMappingProfile.cs +++ /dev/null @@ -1,13 +0,0 @@ -using AutoMapper; -using Tenant.Api.DDD.Domain.Shared; - -namespace Tenant.Api.DDD.Domain; - -public class TenantMappingProfile : Profile -{ - public TenantMappingProfile() - { - - CreateMap(); - } -}