Skip to content

A .NET 8 microservice reference implementation demonstrating modern architectural patterns and integration with technologies like Redis, RabbitMQ (via MassTransit), PostgreSQL (with EF Core), Serilog, .NET Aspire, and more.

Notifications You must be signed in to change notification settings

PatriQ94/CloudTemplate

Repository files navigation

.NET 8 microservice reference implementation

AboutArchitecturePrerequisitesBuild and runRoadmap

About

This project showcases one of many possible implementations of microservices in .NET 8. It incorporates a range of tools and technologies, including PostgreSQL for data storage, Entity Framework Core as the ORM, Redis for caching, and RabbitMQ with MassTransit for event-based communication between microservices. Logging is handled by Serilog, unit testing uses Moq, load testing is done with k6, and API gateways along with .NET Aspire are used to orchestrate the application.

The main purpose of the project is to be used as a reference implementation in case of need.

Architecture

A high-level overview of the system looks like this:

Architecture

It includes several key components:

  • API Gateway: A centralized entry point into the system. Its main role is to route external requests to internal APIs.
  • Product API: A microservice following the VSA architecture. It uses Redis for data caching and its own PostgreSQL database for storage. Additionally, it publishes data to the RabbitMQ message queue.
  • Basket API: A microservice following the VSA architecture. It consumes messages from RabbitMQ.
  • Order API: A microservice following the VSA architecture. It consumes messages from RabbitMQ.
  • Aspire Orchestration: All three APIs, PostgreSQL, Redis, and RabbitMQ are orchestrated using .NET Aspire.

Each of the APIs is built using the Vertical Slice Architecture (VSA), organizing features into cohesive, independently functioning slices.

Api

  • Controllers: The highest layer within an API, consisting of controllers whose job is to receive HTTP requests and return responses. This layer forwards the request data to the service layer using dependency injection (DI).
  • BL: The Business Logic (BL) layer, sometimes called the "service layer," contains all the application's business logic. A service in this layer mostly receives calls from other services within the same layer or from controllers via DI. If necessary, it can call a repository in the DAL to fetch data from the database. This layer is decoupled from the DAL, meaning it is not aware of how or where the DAL layer retrieves data.
  • DAL: The Data Access Layer (DAL) is where all the queries to the database reside. The repository pattern is used in this layer.

Prerequisites

Build and Run

Since this is a reference project focused more on architectural design rather than deployment on platforms like Kubernetes, the easiest and fastest way to run the project is directly from Visual Studio.

  1. Create a folder on your local computer to clone the repository-something like C:\source will work.

  2. Open a command prompt in the newly created folder and clone the CloudTemplate repository from GitHub:

    git clone https://github.com/PatriQ94/CloudTemplate.git
  3. Navigate to the CloudTemplate folder and open CloudTemplate.sln with Visual Studio.

  4. Once the solution is open, right-click the CloudTemplate.AppHost project and select Set as Startup Project if it's not already selected.

  5. Click the green https button at the top of your screen, and that's it - easy peasy!

Roadmap

  • Initial system architecture
  • .NET Aspire configured
  • Product API architecture
  • Basket API architecture
  • Order API architecture
  • API gateway implemented
  • Redis caching implemented
  • MassTransit configured
  • RabbitMQ integrated
  • Serilog logging
  • PostgreSQL integrated
  • EntityFramework configured
  • Unit tests
  • Load tests
  • Documentation
  • TBD

About

A .NET 8 microservice reference implementation demonstrating modern architectural patterns and integration with technologies like Redis, RabbitMQ (via MassTransit), PostgreSQL (with EF Core), Serilog, .NET Aspire, and more.

Resources

Stars

Watchers

Forks