Skip to content

Conversation

@sl-cloud
Copy link
Owner

@sl-cloud sl-cloud commented Oct 21, 2025

Application Layer

  • DTOs (LeadCreatedEvent, ProcessLeadCommand)
  • Validators (ProcessLeadCommandValidator)
  • Handlers (ProcessLeadCommandHandler)
  • DI Registration (ServiceCollectionExtensions)

- Add LeadCreatedEvent DTO for SQS message mapping
- Add ProcessLeadCommand with MediatR IRequest<Unit>
- Add 48 comprehensive unit tests (Domain + Application)
  - 17 tests for Lead entity (validation, equality, immutability)
  - 13 tests for LeadCreatedEvent DTO
  - 18 tests for ProcessLeadCommand
- Remove placeholder test file
- Update README to reflect completed Phase 2

All DTOs are immutable records with full XML documentation.
Follows CQRS pattern and clean architecture principles.
… validation

- Add FluentValidation validator for ProcessLeadCommand
- Validate required fields: TenantId, CorrelationId (GUID), Email, Source
- Validate email format (RFC 5321 compliant, max 254 chars)
- Validate phone numbers with international format support (min 7 digits)
- Validate MessageTimestamp as ISO 8601 format
- Validate Metadata as valid JSON when provided
- Use source-generated regex for optimal performance
- Add ReDoS protection with 1-second regex timeout
- Add 50 comprehensive validator tests covering:
  * Required field validation
  * Format validation (email, phone, JSON, ISO 8601)
  * Length constraints
  * Edge cases (null, empty, whitespace)
  * International phone formats (US, UK, Australia)
  * Multiple error scenarios
  * Integration tests
@sl-cloud sl-cloud changed the title feat(application): add DTOs, commands, and comprehensive tests Application Layer Oct 21, 2025
… pattern

Core Handler Implementation:
- Add ProcessLeadCommandHandler with MediatR IRequestHandler<ProcessLeadCommand, Unit>
- Use C# 12 primary constructor with DI (repository, dateTimeProvider, validator, logger)
- Implement async validation with FluentValidation
- Add idempotency check via CorrelationId (prevents duplicate processing)
- Use IDateTimeProvider abstraction for deterministic UTC timestamps
- Parse optional ISO 8601 message timestamps for audit trail
- Map ProcessLeadCommand to Lead domain entity
- Add comprehensive structured logging (Info, Warning, Error, Debug)
- Implement proper exception handling:
  * ValidationException (logged as Warning, rethrown)
  * DuplicateLeadException (logged as Info, rethrown)
  * Unexpected exceptions (logged as Error, rethrown)
- Support full CancellationToken propagation

Domain & Infrastructure Support:
- Add IDateTimeProvider interface (Domain layer)
- Add SystemDateTimeProvider implementation (Infrastructure layer)
- Add DuplicateLeadException with CorrelationId property

Dependency Injection:
- Add Application.DependencyInjection.ServiceCollectionExtensions
  * Register MediatR handlers from assembly
  * Register FluentValidation validators from assembly
- Add Infrastructure.DependencyInjection.ServiceCollectionExtensions
  * Register IDateTimeProvider as Singleton
- Add FluentValidation.DependencyInjectionExtensions package
- Add Microsoft.Extensions.Logging.Abstractions package
@sl-cloud sl-cloud merged commit 8f7d70a into develop Oct 21, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants