Asset Lifecycle-to-Contract Mapping
Summary
The verified path from an API lifecycle operation, through the aggregate transition and domain event, to the integration contract written to the outbox.
Audience
Engineering, integration, QA, architecture, and security reviewers.
Reference Content
Mapping table
| Lifecycle operation (endpoint) | Aggregate method | Domain event | Integration contract | EventType |
|---|---|---|---|---|
| Create request | Asset.CreateRequest | AssetRequestedDomainEvent | AssetRequestedEvent | AssetRequested |
| Assign / issue | Assign | AssetAssignedDomainEvent | AssetAssignedEvent | AssetAssigned |
| Return | Return | AssetReturnedDomainEvent | AssetReturnedEvent | AssetReturned |
| Reject | Reject | AssetRejectedDomainEvent | AssetRejectedEvent | AssetRejected |
| Mark damaged / mark lost | MarkDamaged / MarkLost | AssetLostOrDamagedDomainEvent | AssetLostOrDamagedEvent | AssetLostOrDamaged |
| Retire | Retire | AssetRetiredDomainEvent | AssetRetiredEvent | AssetRetired |
The endpoints (/asset/requests, /asset/assets/{id}/assign, /return, /reject, /mark-damaged, /mark-lost, /retire) delegate to AssetCommands, which invoke these aggregate methods.
Mapping mechanics
AssetDbContext.Map(IDomainEvent) is a switch over the six domain-event records. For each, it constructs the matching contract with the envelope fields (GUID tenant/user null, SourceService = "asset-service", SchemaVersion = 1) and copies every AssetLifecycleData field into the payload. RecipientEmail is passed as null at emit.
Both mark-damaged and mark-lost map to the single AssetLostOrDamaged contract; the distinguishing detail is carried in Status and Condition.
Completeness guard
Before a contract is returned, EnsureComplete requires a resolvable TenantId, a non-empty AssetId and AssetCode, descriptive AssetName/AssetType, and lifecycle Status/Condition. AssetCompatId is intentionally not required to be greater than zero because AssetRequested is raised before the database key is assigned. A gap throws DomainValidationException, which rolls back the transaction so an incomplete payload never reaches the outbox.
Source References
microservices/src/asset-service/Domain/Asset/Asset.csmicroservices/src/asset-service/Infrastructure/AssetDbContext.csmicroservices/src/asset-service/Api/AssetEndpoints.cs
Related Articles
See Also
Keywords
- Lifecycle mapping
- Domain to contract
- Completeness guard
Revision Information
- Status: Draft
- Last reviewed: 2026-07-17
- Review cycle: Quarterly