文章目录
一、轻松实现命令查询职责分离模式(CQRS)
1.自定义命令类
代码如下(示例):
class CustomCommand : IRequest<long>
{
public string Name {
get; set; }
}
2.自定义实现IRequestHandler的类
CustomCommandHandler 通过泛型参数来关联CustomCommand
代码如下(示例):
class CustomCommandHandler : IRequestHandler<CustomCommand, long>
{
public Task<long> Handle(CustomCommand request, CancellationToken cancellationToken)
{
Console.WriteLine($"CustomCommand执行命令:{request.Name}");
return Task.