Solution Structure for a DDD Application: Overview

Description Article
Summary

A robust .NET application solution following a multilayered software architecture can be obtained combining DDD concepts, service oriented architecture  (SOA) concepts and object-oriented design (OOD).

Due to performance issues for querying summarized data, the CQRS principle is considered: The load operation, through the repository, of an business aggregate root entity it is also possible through directly request  summarized data at application layer due to separation of updates and query operations (Refer to the description of the QueryModel below).

The first diagram gives a first approach of a multilayered architecture model applicable when developing an application of small, medium or large complexity.

 


Description

The proposed application solution structure is described in tha table below.

Depending on the complexity of the application under development, some of the packages may not be required on the .NET solution mounted for the application.

Namespace Naming

Namespace naming used follows the Microsoft namespace naming guidelines:

The used “ProjectName“ terminology can reference a technology, feature or module term. An example would be:

DDDFramework.Finantial.Business.Model.Entities


Solution Structure

Project Purpose Layer Remarks
DDDFramework.ProjectName.
Presentation.Interfaces
Implementation of the WPF application or web interfaces PRESENTATION
DDDFramework.ProjectName.
Presentation.PresentationModel
Implementation of various view models and components to use in the web user interfaces PRESENTATION
DDDFramework.ProjectName.
.ServiceModel
Contains web-service contracts and web-service implementations when domain model is to be exposed as WCF services or old web-services. This project would also contain Data Transfer Object classes representing those domain entity-related data that the service accepts DISTRIBUTED INTERFACES
DDDFramework.ProjectName.
ServiceModel.Host
Contains app.config for the web-services and implements hosting environment through a custom ServiceHost and ServiceHostFactory .NET classes. DISTRIBUTED INTERFACES Required only in case of self-hosting option
DDDFramework.
.ServiceModel.Base
Contains web-service contracts and web-service implementations of usual tasks as login authentication, etc DISTRIBUTED INTERFACES Reusable on every application
DDDFramework.ProjectName.
ServiceGateway
Implementation of web-service clients and components used to communicate with external systems DISTRIBUTED INTERFACES
DDDFramework.ProjectName.
Application.ServiceModel
Implementation of the application services defined as the exposed application API for direct invocation: Class services correspondent to the application use cases are defined here APPLICATION Reusable on other application that includes some of these implemented functionalities
DDDFramework.ProjectName2.
Application.ServiceModel 
One or more packages to be referenced when the definition of the current application services API requires other application services defined initially for some other application APPLICATION
DDDFramework.ProjectName.
Application.Components
Implementation of components required to coordinates the application activity (e.g. Workflows) APPLICATION Reusable on other application that includes some of these implemented functionalities
DDDFramework.ProjectName2.
Application.Components
One or more packages to be referenced when the definition of the current application services API requires other application services and components defined initially for some other application APPLICATION
DDDFramework.Business.Base.
Model.Repositories
Defines abstract and generic repository classes or repository interfaces for definition of specific repository classes DOMAIN Reusable on every application
DDDFramework.Business.Base.
Model.Specifications
Defines generic abstract classes interfaces for later definition of specific specification classes applicable to the project business entities DOMAIN Reusable on every application
DDDFramework.ProjectName.
Business.Model
[.(1)Repositories|(2)Entities|(3)Specifications]

Note: One assembly package, multiple namespaces

Defines (1) specific repository interfaces, (2) entities, value objects, domain services, business domain logic including business rules and validation, or (3) specifications objects DOMAIN The entities can be unique and atomic or re-usable and complex and composed with other business entities defined for some other project.

The classes representing specifications and domain services are named with ubiquitous language 

DDDFramework.ProjectName2.
Business.Model
One or more packages to be referenced when the definition of some of the entities are composed of reusable entities defined initially for some other application DOMAIN
DDDFramework.Base.QueryModel Defines a query execution handler class and a query interface representative of a business query for later implementation QUERY MODEL Reusable on every application.These query handler class will allow upper layers to request and obtain information following the CQRS principle
DDDFramework.ProjectName.
QueryModel.Queries
Contains implementation of the query interface refresenting the business queries and whose result will be encapsulated on data view objects for direct transfer for upper layers QUERY MODEL
DDDFramework.ProjectName.
QueryModel.DVO
Contains collection of simple data view classes to encapsulate results of each business query QUERY MODEL
DDDFramework.Infrastructure.
Base.Persistence
Definition of interfaces for implementation of the Unit Of Wokr design pattern for transaction management classes INFRA
STRUCTURE
Reusable on every application
DDDFramework.Infrastructure.Persistence Implementation of the generic repository interfaces, Unit of Work interfaces and query object-related interfaces INFRA
STRUCTURE
Implemented according the plataform used for persistence
DDDFramework.ProjectName.
Infrastructure.Persistence[.(1)Repositories|(2)Entities]

Note: One assembly package, multiple namespaces

Implementation of (1) specific repository interfaces and (2) data entity objects that are representative of business entities at a low-level whereby they will be persisted to the data source: In case of a data source of type relational database it includes classes directly mapped to the data table columns INFRA
STRUCTURE
  • The need of the data entitiy objects depends of the technology used for persistence. In case of ORM platforms are required form mapping business entities objects to database table columns;
  • Reusable on other application that includes some of these implemented functionalities
DDDFramework.ProjectName2.
Infrastructure.Persistence
Must be referenced when the persistence of some of the business entities in the model requires reusable data entities defined initially for some other application INFRA
STRUCTURE
DDDFramework.Infrastructure.
Base.Common
Implementation of cross-cutting services as exception handling policies, logging, performance counters, configuration, and tracing.Components which perform authentication, authorization, and validation are also implemented here. INFRA
STRUCTURE
Reusable on every application
DDDFramework.ProjectName.
Infrastructure.Common
Implementation of specific cross-cutting services used in the context of the current application and that may be used on all the application layers INFRA
STRUCTURE


Project Dependency

The project / namespaces dependency is shown in the diagram below:

 

Project/Package Reusability
Supposing that the application under development by Microsoft for a specific Client (e.g. name “Amazon“):
  1. uses the already implemented Finantial business package to manipulate invoices within the shopping cart; and
  2. defines a more complex multimedia business model then the defined base company’s Multimedia business package to manipulate multimedia items within the shopping cart
then the mounted solution for the Client application must include the following features:
Project Purpose Layer Remarks
DDDFramework.Amazon.ShoppingCart.
Application.ServiceModel
Implementation of the application services defined as the exposed application API for direct invocation to manage the Shopping Cart APPLICATION
DDDFramework.Amazon.ShoppingCart.
Application.Components
Implementation of components required to coordinates the application activity (e.g. Workflows) APPLICATION
DDDFramework.Microsoft.Finantial.
Application.ServiceModel
Implementation of the application services defined as the exposed application API for direct invocation by the Amazon application services to manage invoices APPLICATION Reference required on the Amazon solution, application layer, for compilation
DDDFramework.Microsoft.Finantial.
Application.Components
Implementation of components required to coordinates the application activity (e.g. Workflows) when managing invoices through the Amazon application services APPLICATION Reference required on the Amazon solution, application layer, for compilation
DDDFramework.Amazon.ShoppingCart.
Business.Model
Defines specific repository interfaces, entitiesvalue objectsdomain services, specifications, business domain logic including business rules and validation DOMAIN Represents the business model related to the shopping cart concept
DDDFramework.Amazon.ShoppingCart.
QueryModel.Queries
Contains implementation of the query interface refresenting the business queries and whose result will be encapsulated on data view objects for direct transfer for upper layers QUERY MODEL Represents the business queries implemented to the shopping cart concept
DDDFramework.Amazon.ShoppingCart.
Infrastructure.Persistence
Implementation of specific repositories and data entity objects that are representative of business entities at a low-level whereby they will be persisted to the data source INFRA
STRUCTURE

DDDFramework.Microsoft.Multimedia.
Infrastructure.Persistence
Implementation of specific repositories and data entity objects representative of Microsoft Multimedia. These data objects will be re-used to persist part of the Amazon’s Multimedia business entities INFRA
STRUCTURE
Reference required on the Amazon solution, infrastructure layer, for compilation