DS-003: Cross-cutting Design Patterns¶
| Property | Value |
|---|---|
| ID | DS-003 |
| Version | 1.0 |
| Status | Draft |
| Author | |
| Approved By | |
| Date |
Purpose¶
This document describes cross-cutting design patterns used throughout Essert.MF. All patterns are documented in detail in the arc42 cross-cutting concepts section.
arc42 Cross-References¶
| Pattern | arc42 Section | Key Content |
|---|---|---|
| Entity pattern | 08 s8.1 | IEntity, IAggregateRoot, ValueObject |
| Repository pattern | 08 s8.2 | Generic repository, specialized repos |
| CQRS pattern | 08 s8.3 | Command/Query handlers |
| Unit of Work | 08 s8.4 | Cross-database transaction coordination |
| CRC integrity | 08 s8.5 | ICrcService, BuildCrcContent, CalculateCrc32 |
| Error handling | 08 s8.8 | DomainException hierarchy, API error responses |
| Logging | 08 s8.9 | Structured logging with ILogger |
| Testing patterns | 08 s8.10, s8.13 | Test base classes, TestDataFactory |
| Real-time events | 08 s8.11 | ICurrentMessageEventService, System.Reactive |
| DI registration | 08 s8.7 | ServiceCollectionExtensions |
| ADR-003 | 09 | AUTO_INCREMENT UID pattern |
| ADR-007 | 09 | Generic parameter repository |
GxP-Critical Patterns¶
The following patterns directly support GAMP5 data integrity requirements:
CRC Integrity Pattern (URS-DAT-001.2)¶
The two-phase insert pattern ensures data integrity for all entities: 1. Insert with UID=0, SaveChanges (gets AUTO_INCREMENT UID) 2. Calculate CRC from UID + all business fields 3. Update entity with CRC, SaveChanges
This is enforced in every repository's Create method and is the primary defense against data tampering.
Design decision: ADR-003 Implementation: arc42/08 s8.5 Runtime flow: arc42/06 s6.4
Unit of Work Pattern (URS-DAT-001.4)¶
Cross-database transaction coordination prevents partial data states: - BeginTransaction on all involved databases - Commit all on success, Rollback all on failure - Ensures atomicity across db_productparameter + db_changelogs
Implementation: arc42/08 s8.4
Generic Parameter Repository (URS-PAR-001.3)¶
Ensures consistent behavior across all 15+ parameter types: - Base class implements common CRUD, CRC, version queries - Type-specific repositories only override CRC content building - Reduces risk of inconsistent implementations
Design decision: ADR-007
Design Verification¶
These patterns are verified through: - Domain tests (151): Entity behavior, value objects, domain events - Application tests (678): Handler logic with mocked repositories - Infrastructure tests (229): Repository operations with real database - API tests (273): Full HTTP request/response cycle