GithubHelp home page GithubHelp logo

cleanddd's Introduction

Overall

https://www.youtube.com/watch?v=fhM0V2N1GpY&list=PLzYkqgWkHPKBcDIP5gzLfASkQyTdy0t4k&index=1&t=0s

https://www.youtube.com/watch?v=tLk4pZZtiDY

https://www.youtube.com/watch?v=fO2T5tRu3DE

Some commands

Build / Run / Test the solution

dotnet build
dotnet run
dotnet test

Add a nuget package to a project

dotnet add ./Naomi.Application/ package  Microsoft.Extensions.DependencyInjection.Abstractions
dotnet add ./Naomi.Infrastructure/ package  Microsoft.Extensions.DependencyInjection.Abstractions
dotnet add ./Naomi.Api/ package  Microsoft.Extensions.DependencyInjection.Abstractions
dotnet add package Microsoft.Extensions.DependencyInjection

Run a project

dotnet run --project ./Naomi.Api/

Add a project reference

dotnet add ./Naomi.Api/ reference ./Naomi.Infrastructure/

Add a webapi project

dotnet new webapi -o Naomi.Api

Add a library project

dotnet new classlib -o Naomi.Contracts

Add a project to a solution

dotnet sln add `ls -r **/*.csproj`

Setup the clean architecture solution

The Clean Architecture is:

  • Presentation
  • Application (this is where the use cases live)
  • Domain (this is where the business entities and business logic live)
mkdir src
cd src

Create the Domain (layer) project and add it to the solution

dotnet new classlib -o ./src/cleanDDD.Domain
dotnet sln add ./src/cleanDDD.Domain/cleanDDD.Domain.csproj 

Create the Domain Unit Tests project and add it to the solution

dotnet new xunit -o ./tests/cleanDDD.DomainUnitTests
dotnet sln add ./tests/cleanDDD.DomainUnitTests/cleanDDD.DomainUnitTests.csproj
dotnet add ./tests/cleanDDD.DomainUnitTests/ reference ./src/cleanDDD.Domain/

Add a feature folder inside to match the feature / Aggregate Customers

mkdir ./tests/cleanDDD.DomainUnitTests/Customers
touch ./tests/cleanDDD.DomainUnitTests/Customers/CustomerTests.cs

Create the Application (layer) project and add it to the solution, make it depend on the Domain layer (but Domain layer cannot depend on another layer)

dotnet new classlib -o ./src/cleanDDD.Application
dotnet sln add ./src/cleanDDD.Application/cleanDDD.Application.csproj 
dotnet add ./src/cleanDDD.Application/ reference ./src/cleanDDD.Domain/

Add MediatR and FluentValidation to the Application layer

cd src/cleanDDD.Application/
dotnet add package MediatR
dotnet add package FluentValidation.DependencyInjectionExtensions

Create the Infrastructure (layer) project and add it to the solution, make it depend on the Application layer and Domain layer

dotnet new classlib -o ./src/cleanDDD.Infrastructure
dotnet sln add ./src/cleanDDD.Infrastructure/cleanDDD.Infrastructure.csproj 
dotnet add ./src/cleanDDD.Infrastructure/ package Microsoft.Extensions.DependencyInjection.Abstractions
dotnet add ./src/cleanDDD.Infrastructure/ reference ./src/cleanDDD.Application/ ./src/cleanDDD.Domain/

Create the Presentation (layer) project and add it to the solution, make it depend on the Application layer and Domain layer

dotnet new classlib -o ./src/cleanDDD.Presentation
dotnet sln add ./src/cleanDDD.Presentation/cleanDDD.Presentation.csproj
dotnet add ./src/cleanDDD.Presentation/ package Microsoft.Extensions.DependencyInjection.Abstractions
dotnet add ./src/cleanDDD.Presentation/ reference ./src/cleanDDD.Application/ ./src/cleanDDD.Domain/

Create the WebAPI project and add it the to the solution

dotnet new webapi -o ./src/cleanDDD.WebApi
dotnet sln add ./src/cleanDDD.WebApi/cleanDDD.WebApi.csproj
dotnet add ./src/cleanDDD.WebApi/ reference ./src/cleanDDD.Presentation/ ./src/cleanDDD.Application/ ./src/cleanDDD.Infrastructure/

Create a Domain model

We convert a domain model to classes to represent the entities.

We'll use tactical patterns to design our initial model and then impose some constraints:

  • Aggregate (Orders, Products, Customers)
  • Entity
  • Value

Orders

  • Order
  • LineItem

Products

  • Product
  • Category

Customers

  • Customer

We create a feature folder for each of our Aggregates to encapsulation our Entities and Values and other behaviours from our Domain model, in our Domain layer project. By organising our domain model around features / Aggregates we're going to have a much more cohesive domain model where everything that is tightly coupled is sitting together inside of the same folder.

We create an Entity to represent our Customer and provide it with a few attributes that can identify it as a Customer.

cleanddd's People

Contributors

rorycawley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.