A ready-to-use .NET 8 Web API solution template for quickly starting new projects with best practices and a clean architecture.
-
Clean architecture and folder structure
-
Pre-configured for RESTful APIs
-
Easily customizable solution and project names (__SolutionName__)
-
Supports dependency injection, logging, and configuration out of the box
-
Integrated Entity Framework Core 8 (Code-First) setup
-
Auditable entities with CreatedBy, CreatedOn, UpdatedBy, and UpdatedOn
-
Ready for JWT Authentication integration
-
Ready for Docker and CI/CD deployment
Clone or download this repository, then run the following command in the root directory:
dotnet new --install {dotenet-api-boilerplate} .
This will install the template locally on your machine.
To create a new solution using this template:
dotnet new dotnetapiboilerplate -n YourSolutionName
Replace YourSolutionName with your desired project name.All placeholders (__SolutionName__) will be automatically replaced.
Navigate to your new solution directory and run:
dotnet build dotnet run --project src/YourSolutionName.Api
This template includes a ready-to-use EF Core setup with:
-
AppDbContext (infrastructure layer)
-
Repository & Unit of Work pattern
-
Auditable and soft-delete support
-
Optional data seeding
Follow these steps to generate and apply migrations:
Edit the appsettings.json file in your API project (YourSolutionName.Api) and set your connection string:
{ "ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=YourSolutionNameDb;Trusted_Connection=True;TrustServerCertificate=True;" } }
dotnet tool install --global dotnet-ef
From the solution root, run:
dotnet ef migrations add InitialCreate --project YourSolutionName.Infrastructure --startup-project YourSolutionName.Api
dotnet ef database update --project YourSolutionName.Infrastructure --startup-project YourSolutionName.Api
After running the update, open your SQL Server and verify:
-
Your database (e.g., YourSolutionNameDb) is created
-
Tables such as Flights and __EFMigrationsHistory exist
Whenever you modify domain entities, simply run:
dotnet ef migrations add AddNewEntity --project YourSolutionName.Infrastructure --startup-project YourSolutionName.Api dotnet ef database update --project YourSolutionName.Infrastructure --startup-project YourSolutionName.Api
You can apply migrations automatically when the API starts by adding the following snippet in your Program.cs:
using (var scope = app.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService(); db.Database.Migrate(); }
This ensures the database is up-to-date each time you deploy.
docker build -t your-solution-name-api . docker run -d -p 8080:80 --name your-solution-name-api your-solution-name-api
Your API will be available at http://localhost:8080.
-
Modify the Dockerfile to change build or runtime options.
-
Use environment variables for configuration (e.g., connection strings, JWT settings).
-
Update namespaces, references, and configuration for your project.
-
Add custom repositories, services, or modules as needed.
-
Extend AppDbContext for new entities and relationships.
Contributions are welcome! Please open issues or submit pull requests for improvements or bug fixes.
This project is licensed under the MIT License.