Skip to content

syaifulnizamyahya/AspireBestPractice

Repository files navigation

Building enterprise class web API using ASP.NET Core with .NET 9.0

Objective

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.


Overview

  • 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 Target Overview
  • As of now, this project does not cover securing your Web Api. For securing enterprise-class Web API, check out OWASP.

Click for screenshots

Aspire main orchestration page Aspire1 Scalar Web Api Documentation page Web Api1 Docker Desktop Docker1 Get all products Getall Get a product by Id Getbyid Create a product Create Product Update a product Update Delete a product Delete Console logs Console Logs Structure logs Structure Logs Traces Traces1 Traces2 Metrics Metrics pgAdmin Pg Admin pgWeb Pg Web

Prerequisites

You need the following installed locally:

  • .NET 9.0
  • Docker Desktop
  • Visual Studio 2022

Basic project features

  • Aspire orchestration features
    • Listing of Aspire resources Aspire Resource Listing
    • Console logs of each resources Aspire Console Logs
    • Structured view of logs for each projects Aspire Structured Logs
    • Traces Aspire Traces
    • Metrics Aspire Metrics
  • Scalar Web API documentation features
    • Get all products Getall
    • Get a product by Id Getbyid
    • Create a product Create Product
    • Update a product Update
    • Delete a product Delete
    • Models information Models Info
  • Product model class Product.cs
  • Database context AppDbContext.cs
  • Controller ProductController.cs
  • Service ProductService.cs

Technology And Best Practices

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published