Set of definitions and protocols that will be use to develop a Web API following the Domain Driven Design pattern.
_This document will allow you to understand the architecture and components of this project.
To execute this project you will need the following packages installed in your computer:
- Visual Studio 2019
- NET Core 3.1
This project is splitted in diferent layers using the Clean Architecture methodology described here (https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/common-web-application-architectures). Here you can find an explanation of each layer:
- WhiteLabel.WebAPI: It contains the API controllers. Don't add business logic here. API credentials, connection string database or any other sensitive information shouldn't be stored in the appsettings.json file, use the secrets.json file for this purpose.
- WhiteLabel.Domain: It contains the high business logic: Entities, Events, Specifications, etc. This layer has to remain isolated from the others and can't contain any reference to any other project.
- WhiteLabel.Application: It contains the low business logic: DTOs, Services, Interfaces, etc. This layer has to remain isolated from the others, it will contain only a reference to WhiteLabel.Domain
- WhiteLabel.Infrastructure.Data: It contains the data classes (Repositories). In this project we will work with a Generic class GenericRepository and we won't need to add a repository class per entity.
- Infrastructure.MigrationHelper: It contains the nuget package Microsoft.EntityFrameworkCore.Tools necessary to be able to execute the EF CodeFirst commands like Add-Migrations, Update-Database, etc.
- Infrastructure.DependencyInjection: It contains all the dependecy injections. If you add a new service or repository class, you will need to add the injection here using AutoFac. By default all services created in WhiteLabel.Application that inherits from IBusinessService interface will be injected automatically.
- WhiteLabel.Infrastructure.Events: It contains the classes to manage the events. TODO. Define better
TODO. Explain the code of Startup and Program classes
TODO. Explain the error management and the Response and GenericError classes
TODO. Explain how data validation is managed using FluentValidation
TODO. Explain how mapping classes
TODO. Explain how to work with Events
TODO. Explain how to add a new CRUD (Entity, Specifications, Events, DTO, Service, Validation, Controller, etc.)
If you are going to add some code to this project, it's very important that you follow these rules:
- Apply the SOLID principles: SRP, OCP, LSP, ISP and DIP.
- Leblanc’s law: Later equals never. If you see a mess, fix it.
- The Boy Scout rule: “Leave the campground cleaner than you found it”.
- The Stepdown rule: Each function introduces the next.
- The Einstein rule: Make it as simple as possible but not simpler.
- Names mean one thing and only one thing.
- Single level of abstraction. One method, one thing.
- Comments are to compensate our failure to express ourself in code.
- Demeter's law: Do not accept candies from strangers
- Murphy's law: If something can go wrong, it will. (Be pessimistic)
To be able to execute the EF commands you will need to follow these steps:
- Select project Infrastructure.MigrationHelper as startup project in solution explorer.
- Open console packet manager (PM) and select Website.Infrastructure.Data as default project.
- Add-Migration <name_migration>
- Update-Database
TODO. In this section we'll explain how to execute the Unit Tests defined in this project.
TODO. Pending to add information.
https://github.com/zkavtaskin/Domain-Driven-Design-Example [Zan Kavtaskin] https://github.com/ardalis/ddd-guestbook [Steve Smith]
Oscar Rodriguez - oscar.chelo@gmail.com
https://oscarchelo.blogspot.com/
https://www.linkedin.com/in/oscar-rodriguez-lopez-70b2a337