Layer Overview
Location:~/workspace/source/Chapi/Domain/
Responsibilities:
- Define core business entities
- Establish repository interfaces (contracts)
- Define domain models and value objects
- Implement business rules and validation
- Remain framework-agnostic and testable
Core Components
Entities
Entities represent core business objects with identity and lifecycle.Repository Interfaces
Repository interfaces define contracts for data access without implementation details.Result Pattern
Chapi uses the Result pattern to handle success/failure without exceptions.Domain Models
Models represent data structures without identity or behavior.Enumerations
Domain-level enums define valid states and options.Domain/Enums/
Domain Services
Domain services encapsulate business logic that doesn’t naturally fit in entities.Dependency Flow
Key Points:- Domain Layer is at the center
- No dependencies on external layers
- All layers depend on Domain contracts
- Infrastructure implements Domain interfaces
Design Patterns
Repository Pattern
Abstracts data access through interfaces like
IGitRepositoryResult Pattern
Type-safe error handling without exceptions
Value Objects
Immutable models like
GitCommit with validationDomain Services
Business logic services like
AvatarCacheServiceTesting Strategy
The Domain Layer is highly testable due to its isolation:Best Practices
Keep Domain Pure
Keep Domain Pure
- No references to UI frameworks (WPF, etc.)
- No references to infrastructure libraries (Entity Framework, etc.)
- Only .NET standard types and domain logic
Use Interfaces for External Dependencies
Use Interfaces for External Dependencies
Define
IGitRepository, IProjectRepository instead of concrete implementationsValidate Business Rules in Entities
Validate Business Rules in Entities
Prefer Result over Exceptions
Prefer Result over Exceptions
Return
Result<T> for operations that can fail gracefullyRelated Documentation
Application Layer
Use cases and application services
Infrastructure Layer
Implementation of domain interfaces
Clean Architecture
Overall architecture principles