- Introduction
- Application Architecture
- Security : JWT Token based Authentication
- Technologies
- Opensource Tools Used
- Swagger: API Documentation
- Postman Collection
- How to run the application
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.
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.
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.
It's based on Distribution Session Store practice for microservices.
- C#.NET
- ASP.NET WEB API Core
- EF Core
- SQL Server
- Automapper (For object-to-object mapping)
- Entity Framework Core (For Data Access)
- Swashbucke (For API Documentation)
- Ocelot (For API Gateway Aggregation)
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".
There is an up to date postman collection in project
- Open the solution (.sln) in Visual Studio 2017 or later version
- Configure the SQL connection string in ServiceA.WebApi -> Appsettings.json file
- 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
- 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.
- Run the following projects in the solution
- Identity.WebApi
- ServiceA.WebApi
- Gateway.WebApi
- EF Core configuared to make database if not existed, so after first time running, it will generate the database.
- Idenity and ServiceA service host and port should be configured correctly in the gateway -> configuration.json