GitHub profile
.NET Framework .NET C# VB.NET LINQ ASP.NET Web API REST SignalR Windows Forms WPF WCF RabbitMQ PHP SQL Server MySQL PostgreSQL MariaDB SQLite MongoDB ADO.NET ORM Entity Framework Dapper XML JSON HTML5 CSS3 Bootstrap JavaScript jQuery Angular React TypeScript NPM Blazor UI/UX Responsive Web Design Redis Elasticsearch GraphQL Grafana Agile Scrum Kanban Windows Server IIS PowerShell Active Directory TFS Azure Automation Software Reverse Engineering Performance Optimization Git Jira/Confluence CI/CD TeamCity SOLID KISS DRY YAGNI
Always will be ready notify the world about expectations as easy as possible: job change page

Using Microservices in .Net Core and Docker container

Created: Nov 7, 2020
Author: Rebai Hamida
Views: 205


During this article, we will learn how to work with the microservice architecture patterns and Docker containers using the .NET Core 3 platform to build a distributed system.

Monolithic vs Microservices Architecture

Before talking about Microservices, we need to understand the difference between traditional application approach and microservices application approach.

Any application is built as a collection of services can be developed, tested, versioned, deployed, and scaled.

For Monolithic applications, Scales is done by cloning the app on multiple servers — VMs.

But for microservices, scales is done by deploying each independently with multiple instances across servers — VMs.

Monolithic vs Microservices Architecture

When developing a server-side application you can start it with a modular hexagonal or layered architecture which consists of different types of components or layers:

  • Presentation Layer — UI layer, this can be a web or mobile or desktop application.
  • Services Layer — responsible for handling HTTP requests and responding with either HTML or JSON/XML (for web services APIs).
  • Business logic Layer — the application’s business logic.
  • Database access Layer — data access objects responsible for access the database.

Despite having a logically modular architecture, the application is packaged and deployed as a monolith.

Monolithic applications are more of a single complete package, having all the related needed components and services encapsulated in one package.

But for microservices, the idea is simple, it consists to split your application into a set of smaller, interconnected services instead of building a single monolithic application. Each microservice is a small application that has its own hexagonal architecture consisting of business logic along with various adapters. Some microservices would expose a REST, RPC or message-based API and most services consume APIs provided by other services. Other microservices might implement a web UI.

Microservices are deployed independently with their own database per service so the underlying.

Microservices architecture and Patterns

One thing about microservices is there are different things that you can use, those technologies for microservices or not but if we choose building and architecting an Microservices there are many patterns most of them are related or coming from domain driven design. I will talk about some of them after.

Microservices architecture stylePatters and technologies

Microservices architecture style

Microservices architecture style

Developers consider Microservices as architectural style that promotes the development of complex applications as a suite of small services based on business capabilities and multiple, independent subsystems in the form of autonomous services.

The following picture shows the microservices architecture style.

There are various components in a microservices architecture apart from the microservices themselves.

We start from a client that interact with a server using an authentication using Identity Provider that manages the identity information and provides authentication services within a distributed network. To ensure this interaction, we need a client’s entry point that is API Gateway. It’s a single point of contact from the client which, in turn, returns responses from underlying microservices and sometimes an aggregated response from multiple microservices, in our schema, we have four services that use the Management that maintains the nodes for the service. And to keep the track of services and service addresses and endpoints, we use Service Discovery.

We have CDN that it a content delivery network to serve static resources. For example, pages and web content in a distributed network and the Static Content is a static resources like pages and web content.

We will talk more in detail about API Gateway:

API Gateway

An API gateway is located between the clients and the services. It acts as a reverse proxy, routing client requests to services. It can also perform various cross-functional tasks such as authentication, SSL termination, and rate limiting. If you do not deploy a gateway, clients must send requests directly to the front-end services.
This creates a coupling between the client and the server. The customer must know how each service has been broken down. these make customer maintenance more difficult and refactoring services.

Now, we need to deploy our services in container, to do that, we will use Docker.

Docker container

Docker and Azure

Docker is a tool that facilitates the creation, deployment, and execution of applications using a containerization approach.

These containers are lightweight and take less time to boot than traditional servers. These containers also increase performance and reduce costs, while providing appropriate management of resources. Another advantage of Docker is that it is no longer necessary to pre-allocate RAM to each container.

Microservice using ASP.NET Core

And before we start modeling our microservices architecture using the strategies and techniques in this course, we need a problem to solve, and this is where this case study comes in. And our case study is based around booking medical appointments.

Prerequisites Environment

  • Visual Studio 2019 or 2017 has built-in support for Docker
  • Windows 10 is required for Docker installation.
  • .NET Core SDK
  • Docker for Windows
  • Docker Tools

Creating an Asp.NET Core 3 Application Solution

I started from this old solution, N- Layered application and it include Web APIs. And we need to change that for Microservices.


N-Layered Monolithic architecture

This application has this structure:

  • Service Layer: include all APIs used and integrate swagger framework.

    Web APIs and Swagger

    User Account API

  • Application and Domain layer: this is the business layer.
  • Two web applications: using MVC 4 and AngularJS.
  • Infrastructure layer is the Database access layer.

We create a new blank solution to include all API project that are our services:

Visual Studio 2019

API with Docker enabled

Or if we can use Docker with an orchestrator Kubernetes, it is ready Core Web application:

Docker and Kubernetes


Push Docker images to Azure Container Registry

HTTP Client Factory

To ensure a resilient cloud application, we need to implement resilient communication with retires.

To implement that, we use the best library for retries and sql breaker is Poly, an open source. So, you can handle or you can implement HttpClient in your application with Http Factory in .net Core.

Orchestrators in Azure

We can use Kubernetes with Docker or Service Fabric if our microservices is based on plain processes and it is more used for stateful services.

Orchestrators in Azure


This article was an overview about Microservices with Docker, microservices allow to evolve deploy and scale parts of the application independently but we can’t use this architecture for small application because it is dedicated to distributed software challenges and for scalable and long term evolving applications.

Jun 26, 2021
We are going to have a look at the steps you need to take to publish an ASP.NET Core application. Then, we are going to have a look on how to set this website up in IIS.Locating the SPA Static...
Mar 19, 2021
Author: Mukesh Murugan
In this article, We will talk about Onion Architecture In ASP.NET Core and it’s advantages. We will also together build a WebApi that follows a variant of Onion Architecture so that we get to see why it is important to...
Feb 7, 2021
Author: Sahan Serasinghe
Caching is the process of storing the data that’s frequently used so that data can be served faster for any future requests. Suppose we have a very lightweight process which talks to another server whose data is not going to...
Jan 2, 2023
Author: Jaydeep Patil
In this article, we are going to discuss the working of CQRS and MediatR patterns and step-by-step implementation using .NET Core 6 Web API.Agenda Introduction of CQRS Pattern When to use CQRS ...
Send message
Your name

© 1999–2023 WebDynamics
1980–... Sergey Drozdov
Area of interests: .NET | .NET Core | C# | ASP.NET | Windows Forms | WPF | Windows Phone | HTML5 | CSS3 | jQuery | AJAX | MS SQL Server | Transact-SQL | ADO.NET | Entity Framework | IIS | OOP | OOA | OOD | WCF | WPF | MSMQ | MVC | MVP | MVVM | Design Patterns | Enterprise Architecture | Scrum | Kanban