Boilerplate – Layered Architecture Rest API using .Net Core 3.1

Introduction

I am planning to create a collection of ready-to-start (development) production-ready solutions/repo boilerplates for .Net core 3.1 REST APIs with different architecture and patterns for various use cases and scenarios.

I am starting the mission with a version of layered architecture with a Repository pattern and entity framework core as ORM. I’ve followed the pattern of microservice and creating individual micro-API’s which can be scalable independently.

I still believe there are scenarios for building REST API using the layered architecture and repository pattern, and of course, this has some relevance now as well.

The code is available to download/clone from github here.

Architecture

The architecture pattern I have followed is the bottom up Presentation Layer -> Business layer -> Data layer , all of the layers are loosely couple using DI container available in .Net Core.

alt text

Highlights

Rest API : .net core 3. Web API Project.

ORM : EntityFrameworkCore 5.0 is used for ORM.

Unit Test: MS Test is used for unit testing the service/business layer classes and Moq framework is used to mock the data layer.

Validation : Fluent validation is used for the validation. (More about Fluent validation here)

Documentation: The swagger documentation has been used and it is configured using Swashbuckle in the middleware. ( More here)

Data Layer : Data layer is built using the repository pattern.

Authentication : AspNetCore.Authentication.JwtBearer Package is used to introduce JWT token-based authentication and authorization. This can be easily replaced with AAD or any other OAuth-based identity provider by configuring the middleware in start-up and changing the AutheticationService in the service layer. As of now, role-based authorization is also implemented using the JWT token.

Run

Once cloned/downloaded you can run this API in IISExpres, IIS or Kestrel servers.

Contribute

Please feel free to contribute to the mission. Suggestions, changes, or fixes are most welcomed, please feel free to clone the repo, create a branch and make your changes and submit a pull request.