Skip to main content

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 methodDomain eventIntegration contractEventType
Create requestAsset.CreateRequestAssetRequestedDomainEventAssetRequestedEventAssetRequested
Assign / issueAssignAssetAssignedDomainEventAssetAssignedEventAssetAssigned
ReturnReturnAssetReturnedDomainEventAssetReturnedEventAssetReturned
RejectRejectAssetRejectedDomainEventAssetRejectedEventAssetRejected
Mark damaged / mark lostMarkDamaged / MarkLostAssetLostOrDamagedDomainEventAssetLostOrDamagedEventAssetLostOrDamaged
RetireRetireAssetRetiredDomainEventAssetRetiredEventAssetRetired

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.cs
  • microservices/src/asset-service/Infrastructure/AssetDbContext.cs
  • microservices/src/asset-service/Api/AssetEndpoints.cs

See Also

Keywords

  • Lifecycle mapping
  • Domain to contract
  • Completeness guard

Revision Information

  • Status: Draft
  • Last reviewed: 2026-07-17
  • Review cycle: Quarterly