.net-core - 如何将 MediatR 与我的业务层分离
问题描述
早上好。
我在我的项目中使用域事件,我发现实现它的最简单方法是使用 MediatR。但我不希望我的项目直接依赖它,我想应用依赖反转来隐藏库。
由于 INotification 接口,在 Mediator 中具有依赖关系的当前代码
public class EmailConfirmedEvent : INotification
{
public Guid PassengerId { get; }
public string Email { get; }
public EmailConfirmedEvent(Guid passengerId, string email)
{
Email = email;
PassengerId = passengerId;
}
}
但我想成为这样:
public class EmailConfirmedEvent : IMyProjectDomainEvent
{
public Guid PassengerId { get; }
public string Email { get; }
public EmailConfirmedEvent(Guid passengerId, string email)
{
Email = email;
PassengerId = passengerId;
}
}
通过某种方式,我需要将中介事件/事件处理程序“转换”为我的项目事件/事件处理程序。
最好的方法是什么。提前致谢。
解决方案
我最终使用 StructureMap 和反射创建了我的域事件自定义代码,以在运行时解析事件处理程序。此处的代码示例:https ://github.com/Henry-Keys/domain-events-sample
推荐阅读
- oauth-2.0 - 使用客户端凭据 OAuth 的 Azure AD Graph API
- binary - Dynamics AX 2012 二进制内核向导安装不显示强制性先决条件
- visual-studio - VS2019由于缺少NuGet Microsoft.NET.Sdk.Functions包无法加载项目,但也无法添加该包
- javascript - 递归爬取并以异步方式写入文件
- android - 如何在 Android 上预计算 mp3 文件?
- python - 如何使用python click实现--version?
- python - 启动 Anaconda Prompt 时缺少指定的配置类型
- python - R 和 Python 中概率之间的差异 (XGBoost)
- git - git“在 X 提交之后或之前”的真正含义是什么?
- java - 如何获取项目的位置并使用光标将其删除?