简体   繁体   中英

.NET MVC 5 and Onion Architecture

I'm writing big project and I want to apply Domain Driven Design (DDD) on it. Here is my projects and explanation:

  • XXX.Domain.Entities - POCO (Plain Old C# Object) classes (Ex: Message.cs)
  • XXX.Domain.Services - The services of the domain

  • XXX.Infrastructure - Infrastructure Interfaces

  • XXX.Infrastructure.Concrete - the impl of the intefaces from XXX.Infrastructure
  • XXX.Infrastructure.DI - Dependency injection modules (Ex: RepositoryModule.cs)

  • XXX.Services - The services of the application (but I don't know where to put the impl)

  • XXX.Tests - Unit tests (Ex: SomeTest.cs)

  • XXX.Web.Ui - MVC5 app

But I can't understand where I should put anyone of those: IMessagesService.cs (BL for model Messages), MessagesService.cs (BL for model Messages), SessionHelper.cs, MessageMapping.cs, IMailerService.cs, MailerService.cs

Also: Where should I put IRepository and GenericRepository (impl)?

You can simply put all implementations into folder Impl within XXX.Services project, if you want to organise your Application Services. There is an option you have instead of creation of new project for implementations only.

在此输入图像描述

But SessionHelper and MessageMapping look like DataAccess specific infrastructure and should be put close to your data access components.

Also, I would put all domain entities and domain services into single project Domain Model . In this case your domain logic won't be split between two projects, XXX.Domain.Entities and XXX.Domain.Services so that all your domain logic will grouped.

EDIT :

There is a good list of differences between domain service and an application services in the post "Services in Domain-Driven Design (DDD)" :

  • Domain services are very granular where as application services are a facade purposed with providing an API.
  • Domain services contain domain logic that can't naturally be placed in an entity or value object whereas application services orchestrate the execution of domain logic and don't themselves implement any domain logic.
  • Domain service methods can have other domain elements as operands and return values whereas application services operate upon trivial operands such as identity values and primitive data structures.
  • Application services declare dependencies on infrastructural services required to execute domain logic.
  • Command handlers are a flavor of application services which focus on handling a single command typically in a CQRS architecture.

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