Hexagonal Architecture with Dotnet 6 — Part 2: Create solution and project layers
We go to Visual Studio and click “Create a new project” and select a “blank solution” and call it OCBeCommerce. We should have something like:
Now, we create some “Solution folders” with the following names: common, core and client.
Common: as its name says, it contains all the code that we can share between the layers of the project.
Core: contains the main layers of the project.
Clients: contains web application and in the future could have console apps, SPA, etc.
Before we continue, we need to know about the main layers of the project.
Main project layers.
Infraestructure: contains all the code about external data access such as: EntityFramework, DapperORM, MongoDB, Redis, RabbitMQ, Gateways, etc… We will create a folder for each type of access. We can also add a GenericRepository to execute basic queries (GetById, GetAll, Create, Update, Delete and more…)
Application: contains all the code about UseCases, CQRS, Presenters, etc…
Domain: contains all the code on Entities, Specific Repository, DTOs and Mappers… This layer is completely independent.
For now, we start creating layers and add “Project References”. Knowing this, we create a DLL for each layer, we should have this:
Is time to add “Project References” and, let’s go:
Domain: it is completely independent, so it has no references. Obviously it will have a reference to the DLLs in the common folder. But it will not have references to the projects within the core.
Application:it just depends of Domain layer and common folder DLLs.
Infraestructure: depends of Domain, Application and common folder DLLs.
Clients (or other consumer/application): depends of Application and Infraestructure(only to add services).
Common.Source DLLs: code and references will be added along the way.
Well, this part ends here. In the next article, we are ready to start with the code.
See you soon.