Skip to content

A Minimal API project built with .NET 9 and integrated with MongoDB, showcasing a scalable Clean Architecture design. It leverages CQRS with MediatR for separation of concerns, FluentValidation for input validation, and includes Swagger for interactive API documentation. πŸš€

Notifications You must be signed in to change notification settings

MohanedZekry/DotNetMongoDbAPI

Repository files navigation

Clean Architecture with Minimal APIs and MongoDB (.NET 9)

Prjoect Developed with .NET 9, Minimal APIs, MongoDB for persistence, and CQRS with MediatR for separation of concerns. The project follows best practices.

Table of Contents

Features

  • Clean Architecture:
    • Clear separation of concerns into Domain, Application, Infrastructure, and Presentation layers.
  • Minimal APIs:
    • Lightweight and fast routing for HTTP endpoints.
  • MongoDB Integration:
    • Flexible NoSQL database with centralized MongoDbContext.
  • CQRS with MediatR:
    • Command-query separation with pipeline behaviors.
  • Validation:
    • Input validation using FluentValidation.
  • Error Handling:
    • Middleware for consistent exception handling.
  • Interactive API Documentation:
    • Auto-generated Swagger UI.

Technologies Used

  • .NET 9: Modern framework for web applications.
  • MongoDB: NoSQL database for scalable data storage.
  • MediatR: CQRS pattern with request/response handlers.
  • FluentValidation: Robust input validation framework.
  • Swagger: API documentation and testing tool.

Project Structure

CleanArchitectureDotNet9
β”œβ”€β”€ CleanArchitectureDotNet9.Domain
β”‚   β”œβ”€β”€ Entities
β”‚   β”‚   └── User.cs
β”‚   └── Common
β”‚       └── BaseModel.cs
β”œβ”€β”€ CleanArchitectureDotNet9.Application
β”‚   β”œβ”€β”€ Common
β”‚   β”‚   β”œβ”€β”€ ValidationBehavior.cs
β”‚   β”‚   └── SystemExceptions.cs
β”‚   β”œβ”€β”€ Features
β”‚   β”‚   └── UserFeatures
β”‚   β”‚       β”œβ”€β”€ Add
β”‚   β”‚           β”œβ”€β”€ AddUserHandler.cs
β”‚   β”‚           β”œβ”€β”€ AddUserMapper.cs
β”‚   β”‚           β”œβ”€β”€ AddUserRequest.cs
β”‚   β”‚           β”œβ”€β”€ AddUserResponse.cs
β”‚   β”‚           └── AddUserValidator.cs
β”‚   β”œβ”€β”€ Behaviors
β”‚   β”‚   └── ValidationBehavior.cs
β”‚   └── Repository
|       β”œβ”€β”€ ICommon
β”‚       β”‚   └── IBaseRepository.cs
|       └── UserRepository
β”‚           └── IUserRepository.cs
β”œβ”€β”€ CleanArchitectureDotNet9.Infrastructure
β”‚   β”œβ”€β”€ Persistence
β”‚   β”‚   └── DotNetContext.cs
β”‚   β”œβ”€β”€ Repositories
β”‚   β”‚   β”œβ”€β”€ BaseRepository.cs
β”‚   β”‚   └── UserRepository.cs
β”‚   └── Settings
β”‚       └── MongoSettings.cs
β”œβ”€β”€ CleanArchitectureDotNet9.Presentation
β”‚   β”œβ”€β”€ Endpoints
β”‚   β”‚   └── UserEndpoints.cs
β”‚   β”œβ”€β”€ Extensions
β”‚   β”‚   β”œβ”€β”€ ErrorHandlerExtensions.cs
β”‚   β”‚   β”œβ”€β”€ CorsExtensions.cs
β”‚   β”‚   β”œβ”€β”€ SwaggerExtensions.cs
β”‚   β”‚   └── ApiBehaviorExtensions.cs
β”‚   └── Program.cs
└── appsettings.json

Installation

To get started with the DotNetFireStore project, follow these steps:

  1. Clone the Repository:
    git clone https://github.com/MohanedZekry/CleanArchitectureDotNet9.git
    

Instructions for Configuration

  1. Open your appsettings.json file in your .NET Core project.

  2. Locate the database configuration section, which should look like this:

    "MongoDB": {
      "ConnectionString": "your-connection-string",
      "DatabaseName": "your-db-name"
    },
    

Replace the placeholders with your actual connections project details:

Usage

After setting up the project, you can start using it to interact with MongoDb.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A Minimal API project built with .NET 9 and integrated with MongoDB, showcasing a scalable Clean Architecture design. It leverages CQRS with MediatR for separation of concerns, FluentValidation for input validation, and includes Swagger for interactive API documentation. πŸš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages