Register environment client¶
This operation registers the baseline, non-secure IEnvironmentClient implementation along with the shared HTTP/host-resolution services it depends on. It is the entry point used by hosts that do not require secure-setting access (contrast with Register secure environment client).
| Field | Value |
|---|---|
| Operation ID | OP-01 |
| Trigger | Application startup code calls RegisterEnvironmentClient() on IServiceCollection. |
| Inputs | None (parameterless). |
| Outputs | Registers ISystemWrapper, IHostResolver, IHttpJsonClient, IEnvironmentClient, and a null ISystemHashService factory. |
| Primary components | IServiceCollectionExtensions.RegisterEnvironmentClient |
| Entry point | src/SAIF.NetCore.ServiceExtensions/SAIF.NetCore.ServiceExtensions/SAIF.NetCore.ServiceExtensions/IServiceCollectionExtensions.cs (L45–55) |
Steps¶
AddHttpContextAccessor()registers the ASP.NET CoreIHttpContextAccessor.- Register Singleton
ISystemWrapper → SystemWrapper(SAIF.NetCore.EnvironmentClient) and SingletonIHostResolver → HostResolver(SAIF.NetCore.EnvironmentClient) — composition-root registration of EnvironmentClient's own infrastructure types, not a delegated operation. - Register Transient
IHttpJsonClient → HttpJsonClient(SAIF.NetCore.HttpClients). - Register Singleton
IEnvironmentClient → BaseEnvironmentClient(BR-SE-01) - On failure: a later secure-setting read against this client throws
EnvironmentClientException.
Origin:
BaseEnvironmentClient's own setting-lookup behavior is documented inGet setting valueandHas setting(SAIF.NetCore.EnvironmentClient); this step only registers a type-based singleton descriptor — construction ofBaseEnvironmentClient(and the bootstrap track/host lookup its constructor performs viaSetup()) is deferred to the first time the DI container resolvesIEnvironmentClient, not performed during this registration call. 5. Register a SingletonISystemHashServicefactory that returnsnull(BR-SE-01), BR-SE-02 - On failure: resolvingISystemHashServiceviaGetRequiredService<ISystemHashService>()throwsInvalidOperationException(MS DI behavior for a factory returningnull).
Process flow¶
This diagram shows the one-time DI registration sequence performed when RegisterEnvironmentClient() is called during service configuration; the registered services' own setting-lookup behavior runs later, at resolution/use.
flowchart TD
Start([RegisterEnvironmentClient called]) --> S1[AddHttpContextAccessor]
S1 --> S2[Register ISystemWrapper / IHostResolver]
S2 --> S3[Register IHttpJsonClient]
S3 --> S4[Register IEnvironmentClient as BaseEnvironmentClient]
S4 --> S5[Register null ISystemHashService factory]
S5 --> EndOk([Non-secure environment client ready])
Failure and edge-case behavior¶
- Attempting to read a secure setting from the registered
BaseEnvironmentClientthrowsEnvironmentClientException. - Resolving
ISystemHashServicewithGetRequiredServicethrowsInvalidOperationExceptionbecause the factory returnsnull.
Related documentation¶
Sources¶
src/SAIF.NetCore.ServiceExtensions/SAIF.NetCore.ServiceExtensions/SAIF.NetCore.ServiceExtensions/IServiceCollectionExtensions.cs