简体   繁体   中英

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.

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. 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.

Should I have a traditional Service Layer that accepts the MediatR interface and have the Controllers have the Service interface instead?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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