Asset Runtime and Startup
Summary
This page documents the asset-service host boot sequence and request middleware order as implemented in Program.cs. It covers dependency registrations, the feature-flag gates evaluated at startup, and the Development-only database migrate and seed step. Knowing this order helps operators reason about what is available when the service accepts traffic and why certain behaviors are environment-dependent.
Audience
- DevOps engineers deploying and starting the service.
- Developers extending registrations or middleware.
- Support engineers correlating startup behavior with runtime symptoms.
Reference Content
Startup sequence
Before the web host builds, the process sets the Npgsql legacy-timestamp switch. A CLI backfill branch exists that runs as a console mode without a web host (see migration and backfill boundaries). When run as a web service, the builder registers dependencies in this order:
AddHrSuitObservability("asset-service")— logging and tracing.AddHrSuitMessaging(config)— event bus and outbox processing.AddHttpContextAccessorandITenantContext→HttpTenantContext.AddDbContext<AssetDbContext>— Npgsql against the asset database.- Scoped registrations:
IOutboxMessageStore→AssetOutboxMessageStore,IUnitOfWork→UnitOfWork,IAuditWriter→AuditWriter,ITimelineWriter→TimelineWriter,IAssetRepository→AssetRepository. - Workflow options and the asset-approval workflow flag (default OFF): when ON, a typed
IWorkflowClient→WorkflowServiceClient(10s timeout); when OFF,IWorkflowClient→NullWorkflowClient. AssetCommands,AssetQueries.- Document options, a typed
DocumentServiceClient(30s timeout),IAssetDocumentGateway→AssetDocumentGateway, andDocumentCommands. AssetCompatService.AddHostedService<OutboxRelayHostedService>.- JWT bearer authentication (multi-key: monolith and Identity signing keys; valid issuers and audiences from config; lifetime validation on; name claim Email, role claim Role), authorization, Swagger, and health checks.
Startup pipeline
Middleware order
| Order | Middleware | Purpose |
|---|---|---|
| 1 | UseHrSuitCorrelationId | Establish correlation id from header |
| 2 | UseSwagger | Serve API description |
| 3 | UseSwaggerUI | Serve API explorer |
| 4 | UseAuthentication | Validate JWT when presented |
| 5 | UseAuthorization | Authorization pipeline |
| 6 | Tenant-missing catch | Map tenant InvalidOperationException to HTTP 400 |
| 7 | MapHealthChecks("/health") | Liveness endpoint |
| 8 | MapHrSuitServiceInfo | Service metadata + correlation id |
| 9 | MapAssetEndpoints | Native/foundation endpoints |
| 10 | MapAssetCompatEndpoints | Compatibility endpoints |
Development-only migrate and seed
In Development only, and unless a skip-migrations flag is set, the service calls Database.MigrateAsync() then DevelopmentSeeder.SeedAsync(). This applies pending EF migrations and seeds a small tenant fixture idempotently. Production migration ownership is Requires confirmation; do not rely on auto-migrate outside Development.
Source References
microservices/src/asset-service/Program.csmicroservices/src/asset-service/Infrastructure/Persistence.csmicroservices/src/asset-service/Infrastructure/DevelopmentSeeder.cs
Related Articles
See Also
Keywords
asset startup, middleware pipeline, service registration, dev migrate seed, feature-flag gate
Revision Information
- Status: Draft
- Last reviewed: 2026-07-17
- Review cycle: Quarterly