Skip to content

Microservices sample architecture for .Net Core Application

Notifications You must be signed in to change notification settings

aliafsahnoudeh/microservices-template-.net-core

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Simple Microservices sample architecture for .Net Core Application

.Net Core 2.2 Sample With C#.Net, EF Core and SQL Server

Introduction

This is a .Net Core sample application and an example of how to build and implement a microservices based back-end ASP.NET Core Web API with C#.Net, Entity Framework and SQL Server.

Application Architecture

The sample application is build based on the microservices architecture. There are serveral advantages in building a application using Microservices architecture like Services can be developed, deployed and scaled independently.The below diagram shows the high level design of Back-end architecture.

  • Identity Microservice - Authenticates user based on username, password and issues a JWT Bearer token which contains Claims-based identity information in it.
  • Service A - It's a sample service with classic CRUD on sample entity.
  • API Gateway - Acts as a center point of entry to the back-end application, Provides data aggregation and communication path to microservices.

alt text

Security : JWT Token based Authentication

JWT Token based authentication is implementated to secure the WebApi services. Identity Microservice acts as a Auth server and issues a valid token after validating the user credentitals. The API Gateway sends the token to the client. The client app uses the token for the subsequent request.

alt text

It's based on Distribution Session Store practice for microservices. alt text

Technologies

  • C#.NET
  • ASP.NET WEB API Core
  • EF Core
  • SQL Server

Opensource Tools Used

  • Automapper (For object-to-object mapping)
  • Entity Framework Core (For Data Access)
  • Swashbucke (For API Documentation)
  • Ocelot (For API Gateway Aggregation)

Swagger: API Documentation

Swashbuckle Nuget package added to the "Transaction Microservice" and Swagger Middleware configured in the startup.cs for API documentation. when running the WebApi service, the swagger UI can be accessed through the swagger endpoint "/swagger".

Postman Collection

There is an up to date postman collection in project

How to run the application

  1. Open the solution (.sln) in Visual Studio 2017 or later version
  2. Configure the SQL connection string in ServiceA.WebApi -> Appsettings.json file
  3. Configure the AppInsights Instrumentation Key in Transaction.WebApi -> Appsettings.json file. If you dont have a key or don't require logs then comment the AppInsight related code in Startup.cs file
  4. Check the Identity.WebApi -> UserService.cs file for Identity info. User details are hard coded for few accounts in Identity service which can be used to run the app. Same details shown in the below table.
  5. Run the following projects in the solution
    • Identity.WebApi
    • ServiceA.WebApi
    • Gateway.WebApi
  6. EF Core configuared to make database if not existed, so after first time running, it will generate the database.
  7. Idenity and ServiceA service host and port should be configured correctly in the gateway -> configuration.json

About

Microservices sample architecture for .Net Core Application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%