简体   繁体   English

CQRS模式的服务层

[英]Service Layer on CQRS pattern

I'm trying to architect an application using CQRS pattern instead of Repositories and Onion architecture instead of n-layers using MVC5 stack. 我正在尝试使用CQRS模式而不是存储库和洋葱架构来构建应用程序而不是使用MVC5堆栈的n层。

I have the following layers right now: 我现在有以下几层:

Web.Data - Contains DbContext 
Web.Model - POCO classes
Web.Service - Implementation of Commands and Queries using MediatR
   --Commands
   -----Request
   -----Handlers
   --Queries
   -----Request
   -----Handlers
Web.UI

I was thinking to put the Business Logic (eg validations) on the Handler classes but I recon that those classes have direct access to EF. 我正在考虑将业务逻辑(例如验证)放在Handler类上,但我认为这些类可以直接访问EF。 Is it still a good place to put those logic? 它仍然是放置这些逻辑的好地方吗?

How about if I have an Emailing logic or shipping logic? 如果我有电子邮件逻辑或运输逻辑怎么样? On traditional layers, they naturally go to Application service having the repositories being injected on that service, how do they'll fit in on the current architecture? 在传统层上,他们自然会转到应用程序服务,将存储库注入到该服务中,它们如何适应当前的体系结构? We don't wanna go repository route since we want to leverage EF as a whole instead abstracting it even more. 我们不想去存储库路由,因为我们想要整体利用EF而不是更多地抽象它。

Should I have a traditional Service Layer that accepts the MediatR interface and have the Controllers have the Service interface instead? 我是否应该拥有接受MediatR接口的传统服务层,并让控制器具有服务接口?

The handler classes should process command and contains logic to orchestrate the completion of task. 处理程序类应该处理命令并包含逻辑以协调任务的完成。 This logic can include delegation to the domain model, persistence and retrieval, and calling out other services (such as shipping, or emailing). 此逻辑可以包括对域模型的委派,持久性和检索,以及调用其他服务(例如传送或电子邮件)。 Note, the command handler is just another flavor of an application service. 注意,命令处理程序只是应用程序服务的另一种风格。 Thus, it should not have direct access to EF and not a place to put the business logic validations. 因此,它不应该直接访问EF,也不应该进行业务逻辑验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM