Are you using or liking this project? Please give a star to support me!
The project currently uses .NET version 9.
- .NET 9
- Entity Framework Core
- MediatR
- FluentValidation
- Mapster
- Bogus (For dummy data)
- xUnit (Testing)
- MailKit (For email functionality)
This project follows the Clean Architecture principles, ensuring a strict separation of concerns between different layers. The aim is to provide a maintainable and scalable structure adhering to SOLID principles.
- Domain: Contains business rules and entities.
- Application: Contains application logic, services, CQRS, and validations.
- Infrastructure: Manages database connections, external services, and other infrastructure concerns.
- Presentation: Handles API and user interface logic (Controllers).
- WebAPI: Orchestrates the presentation layer of the application.
This project includes email-sending functionality using the IEmailService interface and the MailKit library. To enable email sending, you need to configure your appsettings.json
file with your email settings.
Add the following configuration to your appsettings.json
file and customize the values according to your email provider:
"EmailSettings": {
"SmtpServer": "smtp.gmail.com",
"SmtpPort": 587,
"SenderName": "Your Name",
"SenderEmail": "[email protected]",
"Username": "[email protected]",
"Password": "your-email-password"
}
- Abstractions (Base Entity)
- Entities (Domain entities)
- Repositories (Interfaces: IUnitOfWork, IRepository, IProductRepository)
- Features (CQRS, Handlers using MediatR)
- Behaviors (Custom Validation Behavior with MediatR)
- Common (Generic Result Class)
- Services (IJwtProvider, ICacheService, IEmailService, IFileService Interfaces)
- Context (IdentityDbContext and UnitOfWork Implementation)
- Repositories (Repository classes implementing Domain repositories)
- Services (JWT, File Service, Email implementations)
- Options (JwtOptions, JwtSetupOptions, EmailOptions)
- Base API Controller
- Controllers (handling API routes)
- Unit tests using xUnit and Moq.
- MediatR
- FluentValidation
- AutoMapper
- xUnit
- Moq
- Bogus
- MailKit
- Clone the repository:
git clone https://github.com/aheroglu/clean-architecture-starter.git
- Install the necessary NuGet dependencies:
dotnet restore
- Apply the database migrations:
dotnet ef database update
- Run the project:
dotnet run
The Bogus library is used to generate dummy data through the Helper class. The application will populate the database with random data when it starts in development mode.
In Program.cs
, the dummy data generation is triggered like this:
if (builder.Environment.IsDevelopment())
{
Helper.GenerateData(app).Wait();
}
Unit tests are written using xUnit and Moq. Tests cover various CRUD operations and logic through mock repositories and services.
dotnet test
You can continue developing the project by following the layered architecture. For new features, you can add CQRS handlers to the Application layer and define any necessary services in the Infrastructure layer.