Class IdentityRouteContextExtensions
Bridges Identity-owned services (OpenIddict managers, deletion service, options snapshot, …)
from the Identity child into route processors that run inside
the host route context. Mirrors the named-instance pattern that RedbRouteExtensions
uses for IRedbService:
Tsak/InitRoute publishes the Identity child SP's
in the route-context registry under "identity-sp:{name}".Per-exchange consumers ask which creates a fresh
scope on first call within an exchange and caches it under "__redb_scope:identity-sp:{name}"
in . The scope is auto-disposed by
Exchange.ReleaseScopes() alongside named redb scopes (same __redb_scope: prefix
is intentional — it co-opts the framework's existing scope-disposal hook so Identity
scopes get deterministic cleanup without touching redb.Route).
public static class IdentityRouteContextExtensions
Inheritance
Methods
GetIdentityService<T>(IRouteContext, IExchange?, string?)
Resolves T from the Identity child container against a per-exchange
public static T GetIdentityService<T>(this IRouteContext context, IExchange? exchange, string? name = null) where T : notnull
GetIdentityServiceOrDefault<T>(IRouteContext, IExchange?, string?)
Same as but returns null when the requested
public static T? GetIdentityServiceOrDefault<T>(this IRouteContext context, IExchange? exchange, string? name = null) where T : class
RegisterIdentityScopeFactory(IRouteContext, string?, IServiceScopeFactory)
Publishes the Identity child SP's in the route-context
public static IRouteContext RegisterIdentityScopeFactory(this IRouteContext context, string? name, IServiceScopeFactory factory)
Remarks
Why this exists: under .tpkg deployment the host root has no
Identity registrations — those live in a child container built by
. is a
per-exchange scope of the host root, not of the child container, so processors that
reach for exchange.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>()
silently work in single-SP test fixtures (Path 1 in InitRoute) yet throw at runtime
under tpkg loading (Path 2). Going through this helper unifies both paths.
The host SP fallback exists so unit tests that drive a processor without a route context can
still resolve services from the host container; production code always hits the registry.