BaseTemplate DI Extensibility¶
Purpose¶
This page defines the internal implementation contract for DI orchestration extensibility between ConnectSoft.BaseTemplate and specialized templates (for example Identity).
Goals:
- reduce duplicated startup/DI orchestration code
- preserve BaseTemplate defaults as a stable baseline
- allow targeted add/replace behavior through explicit hooks
Compile-time vs runtime: DI hooks affect runtime registration. MSBuild layering (Directory.Build.props, DisableMicrosoftExtensionsStackForMinimalHost.props in extended repos) and Central Package Management control which PackageReference items resolve and which ConnectSoft.Extensions.* optional stacks participate at build time (satellite Condition must match CPM PackageVersion conditions in ConnectSoft.BaseTemplate—see public MSBuild and Central Package Management / Option A). Bump the base-template/ submodule for fixes in Layer 2. See the public Template layering and reuse and ConnectSoft.Extensions catalog.
Standard terms used in this internal guide:
base + addreplace whole stepdefault-preserving hookssubmodule refresh
Core Model¶
Three-layer DI (outside in):
ApplicationModelRegistrationBase(NuGet) — application-model registration shared across templates.MicroserviceRegistrationBase(base-templatesubmodule) — default microservice registration flow and protected virtual hooks for derived templates.- Template-specific registration — derived type in each specialized template overriding hooks as needed.
Host wiring:
MicroserviceRegistrationExtensionsas host entry pointsDefaultMicroserviceRegistrationto preserve default BaseTemplate behaviorMicroserviceRegistrationBaseprotected virtual hooks for derived templates
Extension Patterns¶
base + add¶
Use when derived templates should keep base behavior and append custom registrations.
Examples:
- extra localization resources
- additional named/typed HTTP clients
- template-specific metrics
replace whole step¶
Use when derived templates need different behavior for one registration stage.
Examples:
- health check subset and tags
- problem details mapping strategy
- migration assembly routing and migrator registration
Hook Surface (high-level)¶
MicroserviceRegistrationBase includes hooks across:
- registration staging before/after domain registration
- cross-cutting concerns (localization, HTTP clients, metrics, security, rate limiting, header propagation, request timeouts, compression)
- API stack (problem details, REST infra, Swagger, gRPC)
- persistence/migrations (
GetMigrationAssembly, fluent migrator registration, NH persistence) - observability and health checks
- endpoint mapping and shutdown lifecycle
Extended Template Registration Classes¶
Each extended template provides a single registration coordinator class that inherits from MicroserviceRegistrationBase:
| Template | Registration Class |
|---|---|
| Identity | IdentityMicroserviceRegistration |
| Auth Server | AuthServerMicroserviceRegistration |
| Bot Framework | BotFrameworkMicroserviceRegistration |
| API Gateway | ApiGatewayMicroserviceRegistration |
| Health Checks Aggregator | HealthChecksAggregatorRegistration |
| Microservice Template | MicroserviceTemplateRegistration |
Override Strategy¶
- Replace: The override calls the template's static helper directly without calling
base. Used when the template's method fully covers all registrations. - Base + Add: The override calls
base.RegisterXxx(...)first, then appends template-specific registrations. Typically used forRegisterOptionsandMapMicroserviceEndpoints.
Duplicate Extension Cleanup¶
Infrastructure-only extension files that duplicated base template functionality were removed from all extended templates (e.g., AzureAppConfigurationExtensions, CompressionExtensions, SerilogLoggingExtensions, etc.). These registrations are handled by MicroserviceRegistrationBase hooks.
OpenTelemetryAttributeName Consolidation¶
OpenTelemetryAttributeName.cs was removed from all extended templates. The type is sourced from ConnectSoft.Extensions.Observability NuGet.
Program.cs Alignment¶
All extended templates use the modern Serilog bootstrap pattern:
SerilogBootstrapExtensions.CreateBootstrapLogger()with#if Serilogguards.UseSerilogBootstrap()in the host builder (replaces.UseSerilog(...))- Static
Log.Information(...)/Log.Fatal(...)API (not instanceLogger) - Azure App Configuration null-guard before
options.Connect()
Test Infrastructure Alignment¶
TestStartup.ConfigureServicesconfiguresHealthCheckPublisherOptionswith reduced delay (1s) and period (2s) for faster health status refresh in acceptance tests.BeforeAfterTestRunHooksincludes Azure App Configuration null-guard matching theProgram.cspattern.
Migration Checklist (Derived Templates)¶
- Identify duplicated DI orchestration in derived template
ApplicationModel. - Keep BaseTemplate default flow as source of truth.
- Move template-specific behavior to overrides in your template-specific registration class derived from
MicroserviceRegistrationBase. - Remove mostly identical orchestration code from derived template.
- Remove local copies of types available from shared NuGet packages (e.g.,
OpenTelemetryAttributeName). - Align
Program.csto useSerilogBootstrapExtensions.CreateBootstrapLogger()with#if Serilogguards. - Add Azure App Configuration null-guard in
Program.csand testBeforeAfterTestRunHooks.cs. - Add
HealthCheckPublisherOptionsspeed-up inTestStartup.ConfigureServices. - Respect submodule boundaries:
- do not edit submodule content directly
- refresh submodule to consume BaseTemplate updates
- Verify with build + startup smoke checks (health, endpoints, middleware order).