Microservice Architecture

Updated 15/09/2023

As the name implies, a microservices architecture is an approach to building a server application as a set of small services. That means a microservices architecture is mainly oriented to the back-end, although the approach is also being used for the front end. Each service runs in its own process and communicates with other processes using protocols such as HTTP/HTTPS, WebSockets, or AMQP.

DDD Oriented Microservice

A layered design is implemented in the eShopOnContainers application.

Simply drawn the structure could be:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Ordering.API (application layer)
└─── Authorization
└─── Commands
│ └─── Feature1
│ │ | ...
│ └─── Feature2
│ │ | ...
└─── Common
└─── Contexts
└─── Clients (remote network access)
│ └─── FooService
│ │ | ... (implementation, dto)
└─── Exceptions (application exceptions)
└─── Extensions
└─── Middleware
└─── ModelBinders
└─── Swagger
└─── Services (application logic / algorithms)
└─── Mappers
└─── Queries
│ └─── Feature1
│ │ | ...
│ └─── Feature2
│ │ | ...
└─── Validators
└─── Controllers
└─── Models (controller/view models)
Ordering.Domain
└─── Common
└─── Exceptions (domain exceptions)
└─── Interfaces
└─── Models
│ │ Constants
Ordering.Infrastructure
└───Entity Configurations (if using EF)
└───Repositories

Visually this is:

DDD Oriented Microservice

See https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/ddd-oriented-microservice

Application Layer

Application Layer

Application Layer: Defines the jobs the software is supposed to do and directs the expressive domain objects to work out problems. The tasks this layer is responsible for are meaningful to the business or necessary for interaction with the application layers of other systems. This layer is kept thin. It does not contain business rules or knowledge, but only coordinates tasks and delegates work to collaborations of domain objects in the next layer down. It does not have state reflecting the business situation, but it can have state that reflects the progress of a task for the user or the program. - Eric Evans

Domain model

Domain Layer

Domain Model Layer: Responsible for representing concepts of the business, information about the business situation, and business rules. State that reflects the business situation is controlled and used here, even though the technical details of storing it are delegated to the infrastructure. This layer is the heart of business software. - Eric Evans

Infrastructure Layer

Infrastructure Layer

The infrastructure layer is how the data that is initially held in domain entities (in memory) is persisted in databases or another persistent store. An example is using Entity Framework Core code to implement the Repository pattern classes that use a DBContext to persist data in a relational database. - docs.microsoft.com

Tests to enforce see Enforce microservice architecture

References