這是一個根據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