The primary objective of this project is to develop an enterprise-class Web API using ASP.NET Core with .NET 9.0, adhering to industry-leading practices and leveraging cutting-edge technologies. The project will be structured and implemented following a robust foundation built on:
- Clean Architecture and Domain-Driven Design (DDD) for maintainable and scalable solutions.
- CQRS (Command Query Responsibility Segregation) for clear separation of concerns.
- Repository Pattern and Unit of Work for efficient data access and transactional consistency.
- Mediator Pattern for streamlined communication between components.
- Fluent Validation for clean and reusable validation logic.
- Comprehensive exception handling to ensure resilience and reliability.
- Advanced logging for diagnostics and monitoring.
- API Versioning for backward compatibility and smooth evolution.
- Response Caching to enhance performance.
- Health Checks to monitor application status.
- Entity Framework Core for robust ORM capabilities with SQL Server as the database.
- AutoMapper for object-to-object mapping.
- FluentAssertions, Moq, and xUnit for effective unit testing and ensuring code quality.
- Scalar/OpenAPI for API documentation and client consumption.
- Docker for containerization and portability.
- GitHub Actions and Azure DevOps for CI/CD pipelines and deployment automation.
This combination of design principles, frameworks, and tools will ensure the API is robust, scalable, testable, and production-ready.
- The project will be a simple CRUD operation for a product entity.
- The project will have the following operations:
- Get all products
- Get a product by Id
- Create a product
- Update a product
- Delete a product
- The product entity should has the following properties:
public class Product { public int Id { get; set; } public string Name { get; set; } public decimal Price { get; set; } }
- The project should looks something like this
- As of now, this project does not cover securing your Web Api. For securing enterprise-class Web API, check out OWASP.
Click for screenshots
You need the following installed locally:
- .NET 9.0
- Docker Desktop
- Visual Studio 2022
- Aspire orchestration features
- Scalar Web API documentation features
- Product model class Product.cs
- Database context AppDbContext.cs
- Controller ProductController.cs
- Service ProductService.cs
- Leverage .NET Aspire for orchestrating distributed applications
- Monitoring
- Logging
- Orchestration
- Leverage Scalar for API documentation
- Clean Architecture
- Presentation (ProductApi.Web)
- Application (ProductApi.Application)
- Domain (ProductApi.Domain)
- Infrastructure (ProductApi.Infrastructure)
- Domain Driven Design
- Encapsulation of domain logic within the Product entity
public class Product : Entity
{
public string Name { get; private set; }
public decimal Price { get; private set; }
public Product(string name, decimal price)
{
Name = name;
Price = price;
}
- [X] Separation of application-specific logic into IProductService and ProductService
public interface IProductService
{
Task<IEnumerable<Product>> GetProductsAsync();
Task<Product> GetProductByIdAsync(int id);
- [X] Use of CreateProductDto [CreateProductDto.cs](src/ProductApi.Application/DTOs/Requests/CreateProductDto.cs), UpdateProductDto [UpdateProductDto.cs](src/ProductApi.Application/DTOs/Requests/UpdateProductDto.cs), and ProductDto [ProductDto.cs](src/ProductApi.Application/DTOs/Responses/ProductDto.cs) to manage data between layers.
- [X] Repository and DbContext remain untouched, aligning with persistence ignorance.