This repository provides a template for building applications using the Vertical Slice Architecture with .NET 8. It includes implementations for CQRS, MediatR, global exception handling, Carter library, FluentValidation, EF Core, and the result pattern.
- Getting Started
- Architecture Overview
- Features
- Technologies Used
- Folder Structure
- Setup
- Contributing
- License
- Support
To get a local copy up and running, follow these simple steps.
- Clone the repo
git clone https://github.com/poorna-soysa/vertical-slice-architecture-template.git
- Navigate to the project directory
cd vertical-slice-architecture-template
- Restore dependencies
dotnet restore
This template follows the Vertical Slice Architecture, which organizes code by features rather than technical concerns. Each feature is self-contained, promoting high cohesion and low coupling.
- CQRS: Command and Query Responsibility Segregation.
- MediatR Library: Implements the mediator pattern for handling requests and notifications.
- Global Exception Handling: Centralized handling of exceptions.
- Carter Library: Lightweight library for building HTTP APIs.
- FluentValidation Library: Validation library for .NET.
- Entity Framework Core: Object-relational mapper for .NET.
- Result Pattern: Standardized way of handling operation results.
- Health Checks: Standardized approach for monitoring and assessing the operational status of systems.
- .NET 8
- CQRS
- MediatR
- Carter Library
- FluentValidation
- EF Core
- HealthChecks Library
-
/src: Contains the main application code.
- /Features: Each feature is organized into its own folder, promoting encapsulation.
- /Products: Contains all product related files for the feature.
- /CreateProduct: Logic for creating a product.
- /DeleteProduct: Logic for deleting a product.
- /GetProductById: Logic for retrieving a product by its Id.
- /GetProducts: Logic for retrieving a list of products.
- /UpdateProduct: Logic for updating product details.
- ProductErrors: Contains all product-related error handling.
- FeatureXController.cs: Entry point for HTTP requests related to the feature.
- /Products: Contains all product related files for the feature.
- /Abstractions: Contains shared interfaces and contracts.
- /CQRS: Contains all CQRS abstraction interfaces.
- /Errors: Define Error class.
- /ResultResponse: Standardized response structures for API results.
- /Behaviors: Contains middleware and behaviors that apply to requests and responses.
- /Database: Contains database-related code, including DB Context.
- /Entities: Defines the core data models used throughout the application.
- /Exceptions: Contains the global exception handler for the application.
- /Extensions: Contains extension methods for various classes and services.
- /Migrations: Database migration files for schema updates.
- Program.cs: Application entry point.
- /Features: Each feature is organized into its own folder, promoting encapsulation.
-
/tests: Contains unit and integration tests for the features and common components.
- Configure your database connection string in
appsettings.json
. - Run the application
dotnet run
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
If you find this project helpful, consider buying me a coffee!