This application serves as a comprehensive starting point for your C# development projects. It is built using C# 8 and incorporates several important architectural patterns and libraries, including MediatR, Vertical Slices Architecture, Domain-Driven Design (DDD), Logging, Domain Events, and Validation with Fluent Validation. This README provides an overview of the application structure, features, and how to get started with your development journey.
Before you can start using this starter kit, make sure you have the following prerequisites installed:
- .NET Core SDK
- An SQL server instance
- Your preferred code editor (e.g., Visual Studio, Visual Studio Code)
To get started with the C# Starter Kit, follow these steps:
- Clone this repository to your local machine:
git clone https://github.com/ElMehdiSmiri/VerticalSlicesArchitecture
- Navigate to the project directory:
cd VerticalSlicesArchitecture
- Build the solution:
dotnet build
- Run the application:
dotnet run
Now, your application should be up and running. You can access it in your web browser at http://localhost:7295
.
The C# Starter Kit uses SQL Entity Framework Code First to manage its database schema. Here's how to set up and apply migrations:
-
Database Connection: Open the
appsettings.json
file in theApp/Api
folder and configure your database connection string. Replace<your-connection-string>
with your actual database connection string."ConnectionStrings": { "DefaultConnection": "Server=<your-server>;Database=<your-database>;User Id=<your-username>;Password=<your-password>;" }
-
Apply Migrations: To create and apply the initial database schema, run the following commands:
cd VerticalSlicesArchitecture
dotnet ef migrations add InitialMigration --project App.Infrastructure -s App.Api
dotnet ef database update --project App.Infrastructure -s App.Api
- Update the Database: Whenever you make changes to the domain models or data structures, create a new migration and apply it:
dotnet ef migrations add YourMigrationName --project App.Infrastructure -s App.Api
dotnet ef database update --project App.Infrastructure -s App.Api
The C# Starter Kit follows a modular and organized structure that promotes maintainability and scalability. Here is a brief overview of the key components:
-
App/Api: This directory contains the REST endpoints
-
App/Application: This folder houses the application's use cases, also known as "vertical slices." Each use case is organized in a separate folder and contains commands, handlers, and validation logic.
-
App/Domain: This directory contains the domain entities, aggregates, and domain events.
-
App/Infrastructure: Here, you'll find infrastructure-related code such as database configuration, migrations, and external service integrations.
-
App/test: This directory contains unit tests and integration tests to ensure the application's reliability and correctness.
The C# Starter Kit comes with several features and integrations that you can leverage in your projects:
-
MediatR: Utilizes the MediatR library for handling requests and commands.
-
Vertical Slices Architecture: Promotes organized code by grouping related features together.
-
Domain-Driven Design (DDD): Encourages modeling your application based on the domain's needs and complexity.
-
Logging: Implements a robust logging system for tracking application events and errors.
-
Domain Events: Supports domain events to decouple components and trigger actions based on specific events.
-
Validation with Fluent Validation: Ensures that incoming data meets the required criteria using Fluent Validation.
The C# Starter Kit relies on the following libraries and packages:
For a complete list of dependencies and their versions, please refer to the *.csproj
files in the respective project folders.
Contributions are welcome. If you'd like to contribute, please follow these guidelines:
- Fork the repository and create a feature branch.
- Make your changes and ensure that all tests pass.
- Create a pull request with a clear description of your changes.
The C# Starter Kit is open-source and available under the MIT License. Feel free to use it for your projects and customize it as needed.