WebApis Using DDD
The DDD architecture separates your core business logic (the “Domain”) from technical details like databases (the “Infrastructure”) or web frameworks (the “API”).
Unlike using a flat architecture using a DDD architecture requires your code to have a central entry point which will be your API this will be your base project and with contain the Program.cs. This project will be of the type webapi. We will have other projects which will be of the type classlib. These will complement your base code with their respective functions.
Creating your solution
Let’s assume your solution is named Project1 so this will how you shall create the various projects within your solution. Best practices is to capitalize the solution name and the projectname.
Here is how you can do it using the dotnet CLI
- Creating your base solution
1dotnet new sln -n Project1 - Creating your base project
1dotnet new webapi -n Project1.Api - Creating the complementing solutions
- Adding your various projects to the solution
- Doing it manually
1 2 3 4 5dotnet sln add MyProject.Domain/MyProject.Domain.csproj dotnet sln add MyProject.Application/MyProject.Application.csproj dotnet sln add MyProject.Infrastructure/MyProject.Infrastructure.csproj dotnet sln add MyProject.Api/MyProject.Api.csproj dotnet sln add MyProject.Client/MyProject.Client.csproj - Recursively adding the files in linux based systems
1dotnet sln add **/*.csproj - Recursively adding the files in windows based systems (powershell)
1Get-ChildItem -Recurse *.csproj | ForEach-Object { dotnet sln add $_.FullName }
- Doing it manually
You can also do it via an IDE if doing from a GUI seems better.