Appearance
新建模块
遵循DDD实践
设计源于依赖注入(DI)和控制反转(IOC),依赖倒置
流程:Entity -> Repository -> Service
1.新建实体类
Domain 文件夹下新建DictEntity,继承实体类EntityTenant
约定:实体类以 Entity 命名结尾,Dict可替换成实际业务模块名
[Table(Name = "ad_dict", OldName = "ad_dictionary")]
[Index("idx_{tablename}_01", nameof(DictTypeId) + "," + nameof(Name) + "," + nameof(TenantId), true)]
public partial class DictEntity : EntityTenant
{
/// <summary>
/// 字典类型Id
/// </summary>
[Column(OldName = "DictionaryTypeId")]
public long DictTypeId { get; set; }
/// <summary>
/// 字典类型
/// </summary>
public DictTypeEntity DictType { get; set; }
/// <summary>
/// 字典名称
/// </summary>
[Column(StringLength = 50)]
public string Name { get; set; }
/// <summary>
/// 字典编码
/// </summary>
[Column(StringLength = 50)]
public string Code { get; set; }
/// <summary>
/// 字典值
/// </summary>
[Column(StringLength = 50)]
public string Value { get; set; }
/// <summary>
/// 描述
/// </summary>
[Column(StringLength = 500)]
public string Description { get; set; }
/// <summary>
/// 启用
/// </summary>
public bool Enabled { get; set; } = true;
/// <summary>
/// 排序
/// </summary>
public int Sort { get; set; }
}- 新建仓储接口和仓储实现 接口继承
IRepositoryBase<T>泛型接口
public interface IDictRepository : IRepositoryBase<DictEntity>
{
}接口实现 默认仓储实现AdminRepositoryBase<T>泛型类
public class DictionaryRepository : AdminRepositoryBase<DictEntity>, IDictRepository
{
public DictionaryRepository(UnitOfWorkManagerCloud uowm) : base(uowm)
{
}
}- 服务实现 IDictService接口继承IAppService泛型接口
public partial interface IDictService : IAppService<DictEntity, DictAddInput, DictUpdateInput, DictGetOutput, DictGetListDto, IDictRepository>
{
Task<PageOutput<DictGetPageOutput>> GetPageAsync(PageInput<DictGetPageDto> input);
}DictService继承IDictService接口和AppService泛型类 AppService泛型类实现基础的CRDU
public class DictService : AppService<DictEntity,DictAddInput,DictUpdateInput,DictGetOutput,DictGetListDto,IDictRepository>, IDictService
{
public DictService(IDictRepository repository) : base(repository)
{
}
}需要自定义的方法可以重写对应的方法
public override async Task<IResponseOutput> GetAsync(long id)
{
var result = await _repository.GetAsync<DictGetOutput>(id);
return ResponseOutput.Ok(result);
}