DDD – Domain Driven Development

One of the new challenges I faced at my new job was understanding and adapting to DDD. It can be a bit confusing at first, but as soon as I made sense of it, I couldn’t not recommend it.

In this post i want to explain the basic concept of DDD.

What is DDD?

DDD consists in one domain project that doesn’t depend on anything, while the other projects depend on it. Usually, the domain project contains interfaces, domain entities and utility classes that don’t depend on third parties. Confusing? I’ll explain better in the example below.

Example

A small application to manage tasks (The famous Todos application).

List of projects and their dependencies.

Ps: The projects names should clarify their functions.

Todos – Domain project.
Todos.Manager.Task – Manager with all business rules.
Todos.Repository.Memory – Memory repository to save the data.
Todos.Repository.SqlServer – Sql Server repository to access the data base.
Todos.WebApi – Web api to access the data.

Project list

Code

Unity Integration

To change the repository implementation we just need to change the configuration file. In this way we don’t need to change any code.

Memory Repository:

Memory Repository

Sql Server Repository:

Sql Server Repository

Advantages

  • Simple and robust architecture
  • Dependencies and responsibilities are well defined
  • Works well with Dependency Injection
  • New members adapts easily if they know this development concept

Disadvantages

  • Too much responsibility in one project (Domain Project)

I hope this post can help you to understand better the DDD concept 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook