CleanArchitecture Application代码生成插件-让程序员告别CURD Ctrl+C Ctrl+V
- 2021 年 8 月 20 日
- 笔记
- .NET, CleanArchitecture
这是一个根据Domain项目中定义的实体对象(Entity)生成符合Clean Architecture原则的Application项目所需要的功能代码,包括常用的Commands,Queries,Vaildator,EventHandle,等等一切可以模板化的代码,是不是非常酷。目前这个项目支持我前段时间发布的CleanArchitecture For Razor Page,适用于visual studio.net 2015以上的所有版本。当然你也完全可以通过修改代码来实现适配自己的项目,也欢迎更多优秀的程序员一起参与该项目的开发
介绍
- GitHub: neozhu/CleanArchitectureCodeGenerator
- VS Gallery: CleanArchitecture CodeGenerator
- 适配项目 一个遵循CleanArchitecture原则的Asp.net core轻量级开源项目
Technologies
功能
按实体名称生成符合CQRS和DDD模式的所有代码:
- Events
- $”Events/{name}CreatedEvent.cs”,
- $”Events/{name}DeletedEvent.cs”,
- $”Events/{name}UpdatedEvent.cs”,
- Commands
- $”{nameofPlural}/Commands/AddEdit/AddEdit{name}Command.cs”,
- $”{nameofPlural}/Commands/AddEdit/AddEdit{name}CommandValidator.cs”,
- $”{nameofPlural}/Commands/Create/Create{name}Command.cs”,
- $”{nameofPlural}/Commands/Create/Create{name}CommandValidator.cs”,
- $”{nameofPlural}/Commands/Delete/Delete{name}Command.cs”,
- $”{nameofPlural}/Commands/Delete/Delete{name}CommandValidator.cs”,
- $”{nameofPlural}/Commands/Update/Update{name}Command.cs”,
- $”{nameofPlural}/Commands/Update/Update{name}CommandValidator.cs”,
- $”{nameofPlural}/Commands/Import/Import{name}Command.cs”,
- $”{nameofPlural}/Commands/Import/Import{name}CommandValidator.cs”,
- DTOs
- $”{nameofPlural}/DTOs/{name}Dto.cs”,
- Queries
- $”{nameofPlural}/Queries/Export/Export{nameofPlural}Query.cs”,
- $”{nameofPlural}/Queries/GetAll/GetAll{nameofPlural}Query.cs”,
- $”{nameofPlural}/Queries/Pagination/{nameofPlural}PaginationQuery.cs”,
- EventHandlers
- $”{nameofPlural}/EventHandlers/{name}CreatedEventHandler.cs”,
- $”{nameofPlural}/EventHandlers/{name}UpdatedEventHandler.cs”,
- $”{nameofPlural}/EventHandlers/{name}DeletedEventHandler.cs”,
sample: AddEditProductCommand.cs
namespace CleanArchitecture.Razor.Application.Features.Products.Commands.AddEdit
{
public class AddEditProductCommand: ProductDto,IRequest<Result>, IMapFrom<Product>
{
}
public class AddEditProductCommandHandler : IRequestHandler<AddEditProductCommand, Result>
{
private readonly IApplicationDbContext _context;
private readonly IMapper _mapper;
private readonly IStringLocalizer<AddEditProductCommandHandler> _localizer;
public AddEditProductCommandHandler(
IApplicationDbContext context,
IStringLocalizer<AddEditProductCommandHandler> localizer,
IMapper mapper
)
{
_context = context;
_localizer = localizer;
_mapper = mapper;
}
public async Task<Result> Handle(AddEditProductCommand request, CancellationToken cancellationToken)
{
//TODO:Implementing AddEditProductCommandHandler method
throw new System.NotImplementedException();
}
}
}
已上代码的具体功能我就不在介绍了,代码非常简洁工整。
同时还会生成一份TODO-list方便修改和完善
如何二次开发适配自己项目
选择读取Domain项目中的实体类名
项目代码模板定义
生成的代码
最后
Keep Coding, Enjoy Coding!
如果你喜欢这个项目请上Github点个赞。也欢迎你一起加入开发。
neozhu/CleanArchitectureCodeGenerator