A robust Identity Service implementation using CQRS (Command Query Responsibility Segregation) and DDD (Domain-Driven Design) patterns in .NET. This project demonstrates clean architecture principles with a focus on maintainability and scalability.
If you find this implementation helpful, please consider giving it a star! It helps others discover this pattern and implementation.
The solution follows a clean architecture approach with these key layers:
src/
├── Identity.Api/ # API Controllers and configuration
├── Identity.Application/ # Application logic, commands, and queries
├── Identity.Domain/ # Domain models and business logic
└── Identity.Infrastructure/ # External concerns and implementations
Core business logic and domain models:
Aggregates/- Domain aggregatesCommon/- Base classes and shared components:AggregateRoot.cs- Base for aggregate rootsDomainEvent.cs- Domain event definitionsDomainException.cs- Custom domain exceptionsEntity.cs- Base entity classEnumeration.cs- Smart enum implementationResult.cs- Operation result wrapperValueObject.cs- Value object base class
Entities/- Domain entitiesEvents/- Domain eventsValueObjects/- Value objects for domain models
CQRS implementation and application logic:
Commands/- Command handlers organized by featureCommands/ ├── Users/ │ ├── CreateUser/ │ │ ├── CreateUserCommand.cs │ │ └── CreateUserCommandHandler.cs │ └── UpdateUser/ │ ├── UpdateUserCommand.cs │ └── UpdateUserCommandHandler.csQueries/- Query handlers for data retrievalDomainEventHandlers/- Handlers for domain eventsCommon/- Shared behaviors and interfaces
Implementation details and external concerns:
Configurations/- System configurationsContext/- Database contextData/- Data access implementationExtensions/- Infrastructure extensionsMigrations/- Database migrationsRepositories/- Repository implementationsServices/- External service implementations
- CQRS Pattern: Separate command and query responsibilities
- DDD Implementation: Rich domain model with business rules
- Smart Enums: Using Enumeration pattern for type-safe enums
- Domain Events: Event-driven architecture support
- Clean Architecture: Clear separation of concerns
- Value Objects: Immutable value objects for domain concepts
- .NET 7.0+
- Entity Framework Core
- MediatR for CQRS
- FluentValidation
- AutoMapper
- Clone the repository:
git clone https://github.com/Pavan8374/cqrs-ddd.git- Navigate to the project directory:
cd cqrs-ddd- Build the solution:
dotnet build- Run the application:
dotnet run --project src/Identity.Api/Identity.Api.csproj-
Domain-Driven Design
- Rich domain models
- Encapsulated business rules
- Value objects for immutable concepts
-
CQRS Pattern
- Separated command and query models
- Feature-based command/query organization
- MediatR for command/query handling
-
Clean Architecture
- Clear dependency direction
- Domain layer independence
- Separation of concerns
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
Pavan
- GitHub: @Pavan8374
⭐️ If you found this implementation helpful, please star this repository! It helps others discover this pattern and implementation.