- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我刚刚开始使用 DDD。我正在将域事件放入 CQRS 应用程序中,但我正在执行一项基本任务:如何在域项目中使用 MediatR.INotification 标记接口(interface)而不创建对基础结构的域依赖性。
我的解决方案分为以下四个项目:
MyApp.Domain
- Domain events
- Aggregates
- Interfaces (IRepository, etc), etc.
MyApp.ApplicationServices
- Commands
- Command Handlers, etc.
MyApp.Infrastructure
- Repository
- Emailer, etc.
MyApp.Web
- Startup
- MediatR NuGet packages and DI here
- UI, etc.
我目前在 UI 项目中安装了 MediatR 和 MediatR .net Core DI 包,并使用 .AddMediatR() 将它们添加到 DI,命令为
services.AddMediatR(typeof(MyApp.AppServices.Commands.Command).Assembly);
它从 AppServices 项目扫描并注册命令处理程序。
当我想定义一个事件时,问题就来了。要让 MediatR 处理我的领域事件,它们需要用 MediatR.INotification 接口(interface)标记。
namespace ObApp.Domain.Events
{
public class NewUserAdded : INotification
{
...
}
在这种情况下标记我的事件以便 MediatR 使用它们的正确方法是什么?我可以为事件创建我自己的标记接口(interface),但 MediatR 无法识别那些没有某种方法自动将它们转换为 MediatR.INotification 的方法。
这只是使用多个项目的缺点吗?但是,即使我使用的是单个项目,如果我在域部分中使用 MediatR.INotification,我也会在域中放置一个“外部”接口(interface)。
当我的用户实体继承自 EF 的 IdentityUser 时,我遇到了同样的问题。在那种情况下,网络共识似乎是务实的,继续前进,让轻微的污染避免很多麻烦。这是另一个类似的案例吗?我不介意为了实用主义而牺牲纯洁性,但不仅仅是为了懒惰。
这是我使用的其他软件包会出现的一个基本问题,因此我期待解决这个问题。
谢谢!
最佳答案
您的域层最好不依赖于任何基础设施,但由于绑定(bind)的原因,这在 CQRS 中很难获得。我可以根据我的经验告诉你。但是,您可以最大限度地减少这种依赖性。一种方法是创建您自己的扩展 MediatR.INotification
的 EventInterface
并在整个域代码中使用该接口(interface)。这样,如果您想要更改基础架构,只需更改一个地方。
关于c# - DDD : Referencing MediatR interface from the domain project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47292941/
我已经使用 MediatR 尝试了 CQRS 模式,并且我喜欢应用程序正在转换的干净状态。 在我见过和使用过的所有例子中,我总是这样做 await Mediator.Send(command); 查询
我正在尝试在 .NET Framework 4.6.2 中使用 Autofac 运行 MediatR。 我的注册: public class MediatorModule : Autofac.Modu
有谁知道如何在控制台应用程序中实现 MediatR,以使用 _mediatr.Send(obj) 语法调用处理函数。我正在使用 .Net 6 框架。感谢您的帮助。 最佳答案 首先,您必须安装这些包:
如果我发送 HTTP Get 请求: /api/Company/1 我有一个 OwinMiddleware我在哪里使用 context确定path和 IAsyncRequest 的 json 内容.
我在应用程序中使用 MediatR 和 CQRS。以下两条语句存在于很多模块中,在应用程序中可能会被并发调用(这是一个blazor应用程序)。 await Mediator.Send(new AddI
如何设置 PipelineBehavior 的优先级?我有 3 个管道。我想先执行 AuthorizationPipeline。如果 AuthorizationPipeline 抛出任何 Securi
您好,我已经使用这种带有管道行为的 Mediator CQRS 模式有一段时间了,但现在我遇到了一个问题,即 TResponse 和 TRequest 的通用实现还不够。因此,我试图了解为两个非常具体
我正在使用 Mediatr 开发 ASP.NET Core 2.2 Web API 应用程序。 我有一个看起来像的处理程序 - public class MyQueryHandler : IReque
在查询中对当前用户建模的最佳方法是什么?我正在创建一个 Razor 页面应用程序。在执行查询和命令时,我需要能够附加当前用户。有推荐的方法吗? 最佳答案 下面的方法对我很有效,因为我让用户进入了我的
在 MediatR 的文档中说: Containers that support generic variance will dispatch accordingly. For example, yo
我正在使用 MediatR具有以下类: public class GetPostsRequest : IRequest> { public Int32 Age { get; set; } } pu
我在我的 web api 2 项目中使用 Mediatr 4。与 FluentValidation 和 Unity 一起,我一直在添加管道行为来验证我的请求。 public class Validat
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 3 年前。 Improve this qu
我是 MediatR 的新手,尝试使用管道行为进行请求验证,如果发生任何错误,我遇到的所有示例都会抛出 ValidationException。 下面的代码是验证管道的示例: public class
我意识到我看到了(非常相似的)问题,但这似乎与通常提出的问题略有不同。 我得到了这个通知/通知处理程序 public class GenericEvent : INotification {
我正在研究 CQRS 和 MediatR 库,试图学习一些最佳实践。我遇到的一个问题是命令/查询处理程序中的代码重复。我想知道在处理程序之间共享逻辑的最佳方式是什么。 例子:我有一个定义 ID 属性的
如何让我的 MediatR 通知处理程序触发并忘记? 我的示例代码: public class BackupDatabase : INotification {} public class Backu
我想缓存一些来自 CommandsHandlers 的响应。 我已经使用 IPipelineBehaviour 做到了这一点,但我的请求中只有 5% 确实必须有缓存,而其他 95% 必须跳过此管道。有
我只想装饰一个 MediatR 处理程序。我尝试使用 Behaviours,但 Behaviors 为每个实现 IRequestHandler 的处理程序注入(inject)了装饰器。 public
我尝试使用CQRS制作.NET Core API,但由于MediatR错误而无法构建它: System.AggregateException:'某些服务无法构造(验证服务描述符'ServiceType
我是一名优秀的程序员,十分优秀!