c# - 使用没有分离的服务和存储库的 CQRS 真的会影响代码质量吗?

标签 c# asp.net asp.net-core asp.net-web-api webapi

我想问一个WEB Api架构。我的项目由几个 DDD、CQRS(无 ES)微服务组成。每个服务都有域、应用程序、基础设施和 UI 层。在这个例子中,我将使用 BikeMicroservice。它在 UI 层有 BikeController,它向 MediatR 发送命令或查询对象。在应用层中,我定义了使用相同 BikeService 对象来执行 C/Q 的处理程序(对于每个 C 或 Q)。此外,BikeService 有 BikeRepository,它也使用 EF Core DbContext 对象执行命令和查询。
它是一个合适的 CQRS 设备吗?
我担心服务和存储库对象是否真的应该同时执行查询和命令。我在我的项目中观察到的唯一优势是更薄的 Controller (仅发送查询或命令)。
如何升级微服务的架构?
我应该将 DAL 和服务划分为例如使用 EF Core 的 BikeCommandRepository 和使用 Dapper 的 BikeQueryRepository 吗?

最佳答案

马丁福勒 describes several scenarios CQRS 可能对您有益的地方,以及一些会使事情复杂化的地方:

  • CQRS fits well with event-based programming models. It's common to see CQRS system split into separate services communicating with Event Collaboration. This allows these services to easily take advantage of Event Sourcing.
  • Having separate models raises questions about how hard to keep those models consistent, which raises the likelihood of using eventual consistency.
  • For many domains, much of the logic is needed when you're updating, so it may make sense to use EagerReadDerivation to simplify your query-side models.
  • If the write model generates events for all updates, you can structure read models as EventPosters, allowing them to be MemoryImages and thus avoiding a lot of database interactions.
  • CQRS is suited to complex domains, the kind that also benefit from Domain-Driven Design.

这些是您在决定是否迁移到 CQRS 架构模型时应该评估的一些注意事项。

关于c# - 使用没有分离的服务和存储库的 CQRS 真的会影响代码质量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66476558/

相关文章:

Linux 上的 Asp.net 核心 - dotnet ef 数据库更新失败并出现版本错误

c# - Visual Studio 重构快速操作和重构错误

c# - 套接字自动关闭

c# - 如何使用C#在asp.net页面中的服务器上显示自定义的弹出消息框

asp.net - Javascript JSON.stringify 对象包含数组序列化问题

asp.net - System.Json.DLL 在哪里?

visual-studio - 如果生成单个文件,如何在堆栈跟踪中显示行号

c# - 复活后生成GC?

c# - 调用批处理文件后服务在 WaitForExit 处挂起

docker - asp.net 核心 docker-compose 刷新代码更改