fengling-member-service/.github/instructions/integration-event-converter.instructions.md

49 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
applyTo: "src/Fengling.Member.Web/Application/IntegrationEventConverters/*.cs"
---
# 集成事件转换器开发指南
## 开发原则
### 必须
- **转换器定义**
- 必须实现 `IIntegrationEventConverter<TDomainEvent, TIntegrationEvent>` 接口。
- 转换器负责从领域事件创建集成事件。
- 集成事件使用 `record` 类型定义。
- **注册**:框架自动注册转换器。
### 必须不要
- **直接发布**:不要直接发布集成事件,应通过转换器。
## 文件命名规则
- 转换器应放置在 `src/Fengling.Member.Web/Application/IntegrationEventConverters/` 目录下。
- 转换器文件名格式为 `{Entity}{Action}IntegrationEventConverter.cs`
## 代码示例
**文件**: `src/Fengling.Member.Web/Application/IntegrationEventConverters/UserCreatedIntegrationEventConverter.cs`
```csharp
using Fengling.Member.Domain.DomainEvents;
using Fengling.Member.Web.Application.IntegrationEvents;
namespace Fengling.Member.Web.Application.IntegrationEventConverters;
public class UserCreatedIntegrationEventConverter
: IIntegrationEventConverter<UserCreatedDomainEvent, UserCreatedIntegrationEvent>
{
public UserCreatedIntegrationEvent Convert(UserCreatedDomainEvent domainEvent)
{
var user = domainEvent.User;
return new UserCreatedIntegrationEvent(
user.Id,
user.Name,
user.Email,
DateTime.UtcNow);
}
}
```