Skip to main content

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:

  1. AddHrSuitObservability("asset-service") — logging and tracing.
  2. AddHrSuitMessaging(config) — event bus and outbox processing.
  3. AddHttpContextAccessor and ITenantContextHttpTenantContext.
  4. AddDbContext<AssetDbContext> — Npgsql against the asset database.
  5. Scoped registrations: IOutboxMessageStoreAssetOutboxMessageStore, IUnitOfWorkUnitOfWork, IAuditWriterAuditWriter, ITimelineWriterTimelineWriter, IAssetRepositoryAssetRepository.
  6. Workflow options and the asset-approval workflow flag (default OFF): when ON, a typed IWorkflowClientWorkflowServiceClient (10s timeout); when OFF, IWorkflowClientNullWorkflowClient.
  7. AssetCommands, AssetQueries.
  8. Document options, a typed DocumentServiceClient (30s timeout), IAssetDocumentGatewayAssetDocumentGateway, and DocumentCommands.
  9. AssetCompatService.
  10. AddHostedService<OutboxRelayHostedService>.
  11. 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

OrderMiddlewarePurpose
1UseHrSuitCorrelationIdEstablish correlation id from header
2UseSwaggerServe API description
3UseSwaggerUIServe API explorer
4UseAuthenticationValidate JWT when presented
5UseAuthorizationAuthorization pipeline
6Tenant-missing catchMap tenant InvalidOperationException to HTTP 400
7MapHealthChecks("/health")Liveness endpoint
8MapHrSuitServiceInfoService metadata + correlation id
9MapAssetEndpointsNative/foundation endpoints
10MapAssetCompatEndpointsCompatibility 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.cs
  • microservices/src/asset-service/Infrastructure/Persistence.cs
  • microservices/src/asset-service/Infrastructure/DevelopmentSeeder.cs

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