This is a simple, pre-configured ASP.NET Core project, meant to be adopted and aiming to give you a head start in building restful APIs, based on the three-tier architecture.
To showcase some of its functionality, this project comes with a minimalistic and fictional implementation of a project management application called Plantagoo.
Personally I’ve been repeatedly creating ASP.NET Core API projects from scratch over the last couple of months. Although tech is known to be changing and improving rapidly, I felt the need to create and publish this project to be able to share, reference and build upon it in the future.
Three-Tier Architecture, using Class Libraries per tier
DI-based, asynchronous services, returning generic response object
JWT-based authentication and authorization
PBKDF2-based hashing
Middleware-based global error handling
Restful API endpoints, returning DTOs and HTTP status codes
Implementation of filtering, paging & sorting for API endpoint, which returns lists of objects
Implementation of API endpoint versioning
Entity Framework Core-based data access via POCO entities
AutoMapper-based object-to-object mapping and database query optimization
Security-focused configurability of database connection string and JWT-parameters via environment-based „appsettings.json“-files, secrets and/or environment variables
xUnit-based integration testing, including setup, seeding and teardown of dedicated database
To get this project up and running as is, feel free to follow these steps:
.NET Core 3.1+ SDK
IDE (preferably Visual Studio or Visual Studio Code)
MySQL Server 8.0.20+
Clone this repository
At the root directory, restore required packages by running:
dotnet restore
Open appsettings.{environment}.json
files within Plantagoo.API project to customize the following connection string to your needs (see step 7 for credentials):
server=localhost;Port=3306;database=apiSkeletonDb
For development purposes, enable secret storage by running (If you're used to working with environment variables, fast forward to step 7):
dotnet user-secrets init
If you’re on Windows, goto and open %APPDATA%MicrosoftUserSecrets<user_secrets_id>secrets.json
file.
If you're on Linux/macOS, goto and open ~/.microsoft/usersecrets/<user_secrets_id>/secrets.json
file.
Within this secrets.json file, add the following lines to set your JWT-parameters and to extend your database connection string by adding username and password:
"TokenSettings:Secret": "…", "TokenSettings:AccessExpirationInMinutes": "…", "DB:Username": "…", "DB:Password": "…"
For an Code-First Approach to creating the database, run the following command (make sure your current directory is Plantagoo.Data
):
dotnet ef migrations add InitialCreate
Followed by:
dotnet ef database update
Next, build the solution by running:
dotnet build
Once done, launch the application by running:
dotnet run
Launch https://localhost:5001/swagger/index.html in your browser to view the Swagger documentation of your API
.NET Core 3.1
ASP.NET Core 3.1
Entity Framework Core 3.1
AutoMapper
Swashbuckle
xUnit