This document details the implementation of a robust and standardized ASP.NET Core API using ProWebAPI. It covers key aspects like Swagger integration, dependency injection, standardized responses, versioning, request validation, OData v4 support, global exception handling, and EF Core with UnitOfWork. The guide provides step-by-step instructions for each component.
ProWebAPI
ASP.NET Core API with all proper standards
Standards Implemented
Swagger
Install Swagger
Setup DI
Standard Resoponse for API
Standard response
Versioning
Install Nuget library
Add to dependency container
Decorate the controllers base on the need
Request Validator
Install Nuget library
Register validators on DI
On the 'RequestDto' Namespace, Add the validators along with dto
Build a ValidationFilter
Register the filter and turn off [ApiController] auto 400 Bad Request intercept
AppSettings.json
Configure appsettings for databases
Create 2 ENVIRONMENT configurations
OData v4
To support OData Install the NuGetpackages
Add to service DI for OData
Configure OData
Override [EnableQuery] attribute with [EnableOData] to catch errors and return standard response
Decorate the Action Methord
Query by URL
Global Exception Handler
Create the Middleware
Create an extension methord for app builder
Register the middleware
Response Casing
Allow member casing (which will be in pascal case for props) so that OData query result won't conflict with casing
EF Core + UnitOfWork
Add supporting class libraries
Install the required packages on ProWeb.Data
To run migrations
SET ProWeb.Data as [Startup Project] and run migrations