Skip to content

new ddd

The new ddd is a specialized command that inherits from the new command base class. It creates new projects following the Domain-Driven Design (DDD) architectural pattern building 4 projects: Presentation, Domain, Application and Infrastructure.

The template is built around .NET Aspire. The novel framework Microsoft is developing for streamlining development in ASP.NET Core. It provides a set of tools and libraries that simplify the process of building modern web applications, including microservices. Like resource orchestration, tooling, etc.

To run the project you just need to have docker installed and run the AppHost project. That’s the magic of Aspire!!. It will install the images of all the required services, like databases and message queues. No configuration is required as Aspire will take care of that for you, passing the required connection string to each project on start up.

Options

Option Alias Description Required Example
--name -n Project name Yes --name MyDddProject
--output -o The output directory No --output ./projects/ddd
--presentation -pre API type (FastEndpoints, GraphQL) No --presentation FastEndpoints
--infrastructure -inf Persistence layer (MongoDB, EFCore) No --db-type EFCore
--application -app Application layer type (MediatR) No --application MediatR
--domain -dom Domain layer type (Default) No --domain Default
--db-type -db Database type (SQLServer, PostgreSQL), required if EF Core selected No --db-type SQLServer
--skip-interactive - Skips the interactive prompt and uses the default values for all options No --skip-interactive

Omitting the --output option will create the project in the current directory.

Omitting any other non required option will use the default value.

Usage

Terminal window
apiand new ddd --name MyProject --api-type FastEndpoints --db-type MongoDB

Features

  • Multi-Layer Architecture: Organized into distinct layers (Presentation, Domain, Application, Infrastructure)
  • Domain-Driven Design: Focused on core business logic and domain models
  • Flexible Infrastructure: Support for multiple database options (MongoDB, EF Core with SQL Server or PostgreSQL)
  • Presentation Options: Choose between REST or GraphQL APIs
  • CQRS Pattern: Clean separation of commands and queries with MediatR
  • Dependency Injection: Well-structured service registration and configuration

When to Use

The DDD architecture is ideal for:

  • Complex business domains with rich logic
  • Enterprise-level applications
  • Projects requiring clear separation of concerns
  • Applications expected to grow and evolve over time
  • Systems where business rules change frequently
  • Teams with specialized roles (domain experts, UI developers, etc.)
  • Projects where maintainability and scalability are top priorities