(一)复习(模块注入/minimal api/EF和Dapper实现CQRS)
文章目录
- 项目地址
- 一、模块注入
- 1.1 创建Event模块的统一注册入口
- 1.2 Program里统一调用
- 二、minimal api
- 2.1 创建一个查询controller
- 2.2 注册minimal api节点
- 三、EF实现CreateEvent
- 3.1 EndPoint构建(Presentation)
- 1. 使用ISender创建minimal api
- 2. EndPoint注册
- 3.2 Create请求构建(Application)
- 1. Command类
- 2. CommandHandler类
- 3.3 接口实现(Infrastructure)
- 1. IUnitOfWork实现
- 2. IEventRepository实现
- 3.4 FluentApi验证Command
- 1. 创建验证器
- 3.5 Event模块所有服务和配置注册
- 四、Dapper实现GetEvent
- 4.1 构建GetEvent的Minimal api(Presentation)
- 4.2 GetEventQuery实现 (Application)
- 1. 创建IDbConnectionFactory
- 2. GetEventQuery
- 3. GetEventQueryHandler
- 4.3 接口实现 (Infrastructure)
- 1. IDbConnectionFactory实现
- 2. 注册Dapper服务和数据库服务
- 五、Rich Domain Event实现
- 5.1 创建Entity的抽象
- 1. 创建IDomainEvent
- 2. IDomainEvent实现
- 3. Entity类
- 5.2 Event 领域
- 1. Event实体
- 2. EventCreatedDomainEvent领域事件
- 3.x CQRS的高级使用
项目地址
- 教程作者:
- 教程地址:
- 代码仓库地址:
- 所用到的框架和插件:
dbt
airflow
一、模块注入
- 使用静态类和静态方法对模块进行注入
1.1 创建Event模块的统一注册入口
- 静态类统一注册Event模块
1.2 Program里统一调用
- 调用Event模块里静态类中的各个方法
二、minimal api
2.1 创建一个查询controller
- 创建查询controller
2.2 注册minimal api节点
三、EF实现CreateEvent
3.1 EndPoint构建(Presentation)
1. 使用ISender创建minimal api
- 将上面垂直架构的minimal api改为CQRS,CQRS对数据库进行了解耦
2. EndPoint注册
- 将当前所有Miminal api注册
- 通过EventsModule统一注册
EventEndpoints
3.2 Create请求构建(Application)
1. Command类
- 传入Command,返回Guid
2. CommandHandler类
3.3 接口实现(Infrastructure)
1. IUnitOfWork实现
2. IEventRepository实现
- 实现Domian的层的IEventRepository
using Evently.Modules.Events.Domain.Events;
using Evently.Modules.Events.Infrastructure.Database;namespace Evently.Modules.Events.Infrastructure.Events;
internal sealed class EventRepository(EventsDbContext context) : IEventRepository
{public void Insert(Event @event){context.Events.Add(@event);}
}
3.4 FluentApi验证Command
1. 创建验证器
using FluentValidation;namespace Evently.Modules.Events.Applic