Template repository for a .NET Web Api project.
- Clone this Repository
- Install Project Template
- Create Project with
dotnet new
Clone or download this repository.
git clone https://github.com/ovation22/Api.Project.Template.git
Then run the following command to install this project template:
dotnet new install ./Api.Project.Template
You should now see the api-project
template installed successfully.
Run the following command to create the solution structure in a subfolder named Your.ProjectName
:
dotnet new api-project -o Your.ProjectName
Optionally, you may choose to included additional parameters to better fill out your new project:
dotnet new api-project -o Your.ProjectName \
--appInsights "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus2-0.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus2.livediagnostics.monitor.azure.com/"
Included in the solution:
- .NET 7 Web Api
- Logging
- Repository
- Http client
- Service Bus client
- Event Hub Producer client
- Unit Tests
- Integration Tests
- Benchmark Tests
- Architectural Tests
The Core project is the center of the Clean Architecture design, and all other project dependencies should point toward it. As such, it has very few external dependencies. The Core project should include things like:
- Entities
- DTOs
- Interfaces
- Domain Services
Most of your application's dependencies on external resources should be implemented in classed defined in the Infrastructure project. These classed should implement interfaces defined in Core. The Infrastructure project should include things like:
- Http clients
- Repositories
- Event Hub Producer clients
- Service Bus clients
The entry point of the application is the Api project. The Api project should include things like:
- Program.cs
- Controllers
- Configurations
Test projects are organized based on the kind of test (unit, integration, benchmark, etc.).
Unit tests provide a way to verify and validate functionality of individual methods/components/features. This project contains example tests using xUnit.
Integration testing provides a way to ensure that an application's components function correctly at each level.
Architectural rules can be enforced using NetArchTest, a fluent API for .NET Standard that can enforce architectural rules within unit tests.
Benchmark testing is provided by BenchmarkDotNet, a powerful .NET library for creating and executing benchmark tests.
dotnet run --project ./tests/Api.Project.Template.Tests.Benchmark -c Release