141 lines
4.4 KiB
Markdown
141 lines
4.4 KiB
Markdown
# MyNewProjectName - Clean Architecture Template
|
|
|
|
A Clean Architecture template for .NET 9 applications.
|
|
|
|
## 📁 Project Structure
|
|
|
|
```
|
|
├── MyNewProjectName.Domain # Enterprise Business Rules (Entities, Value Objects, Domain Events)
|
|
├── MyNewProjectName.Application # Application Business Rules (Use Cases, CQRS, Validators)
|
|
├── MyNewProjectName.Contracts # DTOs for external communication (Requests, Responses)
|
|
├── MyNewProjectName.Infrastructure # External concerns (Database, Identity, Services)
|
|
├── MyNewProjectName.WebAPI # Web API presentation layer
|
|
├── MyNewProjectName.AdminAPI # Admin API presentation layer
|
|
└── MyNewProjectName.UnitTest # Unit tests
|
|
```
|
|
|
|
## 🏗️ Architecture
|
|
|
|
This template follows **Clean Architecture** principles:
|
|
|
|
```
|
|
┌─────────────────────────────────────────────────────────┐
|
|
│ Presentation Layer (WebAPI, AdminAPI) │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ Infrastructure Layer (EF Core, Identity, Services) │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ Application Layer (MediatR, AutoMapper, Validators) │
|
|
├─────────────────────────────────────────────────────────┤
|
|
│ Domain Layer (Entities, ValueObjects, Interfaces) │
|
|
└─────────────────────────────────────────────────────────┘
|
|
```
|
|
|
|
### Dependency Rule
|
|
- Inner layers know nothing about outer layers
|
|
- Dependencies point inward
|
|
|
|
## 🚀 Getting Started
|
|
|
|
### Prerequisites
|
|
- .NET 9 SDK
|
|
- SQL Server (or modify connection string for other databases)
|
|
|
|
### Setup
|
|
|
|
1. **Clone and rename the template**
|
|
```bash
|
|
# Clone the repository
|
|
git clone <repository-url> MyNewProject
|
|
cd MyNewProject
|
|
|
|
# Run the rename script
|
|
./rename-project.sh MyNewProject
|
|
```
|
|
|
|
2. **Update connection string**
|
|
|
|
Edit `appsettings.json` in WebAPI/AdminAPI projects:
|
|
```json
|
|
{
|
|
"ConnectionStrings": {
|
|
"DefaultConnection": "Your-Connection-String"
|
|
}
|
|
}
|
|
```
|
|
|
|
3. **Run migrations**
|
|
```bash
|
|
cd MyNewProjectName.Infrastructure
|
|
dotnet ef migrations add InitialCreate --startup-project ../MyNewProjectName.WebAPI
|
|
dotnet ef database update --startup-project ../MyNewProjectName.WebAPI
|
|
```
|
|
|
|
4. **Run the application**
|
|
```bash
|
|
dotnet run --project MyNewProjectName.WebAPI
|
|
```
|
|
|
|
## NuGet Packages
|
|
|
|
### Application Layer
|
|
- **MediatR** - CQRS pattern implementation
|
|
- **AutoMapper** - Object-to-object mapping
|
|
- **FluentValidation** - Validation rules
|
|
|
|
### Infrastructure Layer
|
|
- **Entity Framework Core** - ORM
|
|
- **Microsoft.AspNetCore.Identity** - Authentication/Authorization
|
|
|
|
## 🔧 Key Features
|
|
|
|
- Clean Architecture structure
|
|
- CQRS with MediatR
|
|
- Validation pipeline with FluentValidation
|
|
- Logging pipeline behavior
|
|
- Global exception handling
|
|
- Generic Repository pattern
|
|
- Unit of Work pattern
|
|
- AutoMapper integration
|
|
- Multi-API support (WebAPI + AdminAPI)
|
|
- Auditable entities
|
|
- Soft delete support
|
|
- Domain events support
|
|
|
|
## 📝 Usage Examples
|
|
|
|
### Creating a new Feature
|
|
|
|
1. **Add Entity** in `Domain/Entities/`
|
|
2. **Add Repository Interface** in `Domain/Interfaces/`
|
|
3. **Add Command/Query** in `Application/Features/{FeatureName}/`
|
|
4. **Add DTO** in `Contracts/DTOs/`
|
|
5. **Add Controller** in `WebAPI/Controllers/`
|
|
|
|
### Sample CQRS Structure
|
|
|
|
```
|
|
Application/Features/Sample/
|
|
├── Commands/
|
|
│ └── CreateSample/
|
|
│ ├── CreateSampleCommand.cs
|
|
│ ├── CreateSampleCommandHandler.cs
|
|
│ └── CreateSampleCommandValidator.cs
|
|
└── Queries/
|
|
└── GetSamples/
|
|
├── GetSamplesQuery.cs
|
|
├── GetSamplesQueryHandler.cs
|
|
└── SampleDto.cs
|
|
```
|
|
|
|
## 🔄 Renaming the Project
|
|
|
|
Use the provided script to rename all occurrences of `MyNewProjectName`:
|
|
|
|
```bash
|
|
./rename-project.sh NewProjectName
|
|
```
|
|
|
|
## 📄 License
|
|
|
|
MIT License
|