N9 is a .NET 9 Minimal Web API application emphasizing scalability, resilience, and security.
This project demonstrates a structured approach to building a web API using .NET 9, incorporating:
- Data Layer: Utilizes Entity Framework Core with SQL Server for data management and migrations.
- Service Layer: Contains business logic interfacing between the API and data layers.
- API Layer: Exposes endpoints, integrates middleware, and manages authentication and authorization.
- Entity Framework Core: Database interactions and migrations with SQL Server.
- OpenAPI (Scaler): API documentation and testing interface.
- Polly: Implements resilience strategies like retries and circuit breakers.
- Middleware:
- HTTP request logging.
- Global exception handling with standardized problem details.
- Authentication & Authorization:
- Azure Active Directory integration.
- JWT-based authentication.
├── src/
│ ├── Data/ # Data access layer
│ ├── Services/ # Business logic layer
│ └── Api/ # API layer
├── tests/ # Unit and integration tests
├── N9.sln # Solution file
└── README.md # Project overview
- .NET 9 SDK
- SQL Server
- Docker (optional)
- Azure Active Directory setup for authentication
-
Clone the repository:
git clone https://github.com/joietej/DotNet9WebApiSample.git cd DotNet9WebApiSample
-
Configure the database connection string:
Update the
ConnectionStrings:Sql
inappsettings.json
with your SQL Server details. -
Apply Entity Framework Core migrations:
dotnet ef database update --project src/Data
-
Run the application:
dotnet run --project src/N9.Api
-
Access the API documentation:
Navigate to
http://localhost:5295/api-docs/v1
in your browser.
To run the API as a Docker container, follow the steps below:
-
Build the Docker image:
In the root of your repository, run the following command to build the Docker image:
docker build -t dotnet9webapisample . docker run -d -p 5295:8080 --name dotnet9webapisample dotnet9webapisample
Configure Azure AD settings in appsettings.json
:
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "yourdomain.com",
"TenantId": "your-tenant-id",
"ClientId": "your-client-id",
"CallbackPath": "/signin-oidc"
}
- Polly: Configured for transient fault handling.
- HTTP Logging: Enabled for request and response logging.
- Exception Handling: Standardized error responses using Problem Details.
Contributions are welcome! Please fork the repository and submit a pull request.
This project is licensed under the MIT License.