Construct and configure the client¶
This operation builds a ConnectionClient instance, caches its two injected dependencies, and resolves the DBConnectionAPI service URL, the three engine endpoint segments, and the outbound client-identity headers before the instance is handed to a caller.
| Field | Value |
|---|---|
| Operation ID | OP-DBC-01 |
| Trigger | DI factory in ServiceExtensions.RegisterDBConnectionClient (singleton lifetime), or a direct new ConnectionClient(IHttpJsonClient httpJsonClient, IEnvironmentClient envClient) call |
| Inputs | IHttpJsonClient httpJsonClient, IEnvironmentClient envClient |
| Outputs | A configured ConnectionClient instance |
| Primary components | ConnectionClient constructor, ConnectionClient.Setup |
| Entry point | src/SAIF.NetCore.DbConnectionClient/SAIF.NetCore.DBConnectionClient/SAIF.NetCore.DBConnectionClient/ConnectionClient.cs |
Steps¶
- Initialize the empty connection cache
_connectionsand store the two injected dependencies (IHttpJsonClient,IEnvironmentClient). - Call the
virtualSetup()method. - Read
ServiceUrlfrom configuration keyDBConnectionClient:ServiceUrlvia the injectedIEnvironmentClient.GetSettingValue(key, section)contract (BR-DBC-01). - 3.1. Build a dictionary key from
section/configKeyand load theDBConnectionClientsection into the settings cache if it has not already been loaded. When the standardBaseEnvironmentClientimplementation is registered, loading a section first callsCheckForUpdates, which reloads the whole settings cache only when a periodic timestamp probe (throttled to once perTimeToWaitSeconds, 60 seconds by default) determines the remote EnvironmentAPI'sLastRefreshedis newer than the local value, or unconditionally when the local cache is still empty — it is not an unconditional reload on every call once the standard refresh interval has elapsed. That reload clears the cached settings dictionary but preserves the set of already-loaded section names, then reloads each of them in turn; an exception partway through that per-section reload loop can leave a not-yet-reloaded section still marked loaded with no data behind it until a later refresh succeeds. - 3.2. If the
DBConnectionClientsection is not yet loaded, the standard implementation issues one request to the EnvironmentAPI for it and classifies the result: a null result, an unsuccessful response, or a successful response with no settings collection at all throwsEnvironmentClientException, which propagates out of this operation uncaught; a successful response with zero individual settings is not an error, but it stores nothing and leaves the section unmarked (or removes it if it had previously been marked loaded), so the next call retries the load; only a successful, nonempty result both upserts the returned settings into the cache and marks the section name as loaded. - 3.3. Look the key up in the loaded settings and return its value, or an empty string if the key is not found. For the standard
BaseEnvironmentClientimplementation, a configured developer-settings-override file is checked first and takes precedence over the loaded dictionary; falling through to the dictionary and then to an empty string on a miss means that implementation does not throw for a missing key — this is a property of that registered implementation, not a universal guarantee of theIEnvironmentClientcontract itself.
Origin: Steps 3.1–3.3 are implemented in Load section and Get setting value (
SAIF.NetCore.EnvironmentClient,BaseEnvironmentClient.CheckForUpdates/LoadSection/HandleGetConfigurationSettingsResults/GetSettingFromDictionary) when the host registers the standardBaseEnvironmentClient/SecureEnvironmentClientimplementation, and executed on behalf of this operation. A differently registeredIEnvironmentClientimplementation can resolve the value differently. 4. ReadSqlConnectionEndpoint,PostgreSqlConnectionEndpoint, andOracleConnectionEndpointfrom the sameDBConnectionClientsection (BR-DBC-01). - No null/empty validation is performed — missing values flow unchecked into URL paths built later. 5. Configure the HTTP client's identity:SetClientInfo(ServiceUrl, "DBConnectionClient", EnvClient.ApplicationHost, EnvClient.ApplicationName), which sets the base URL plusClient-User,Client-Name, andApplication-Idheaders (BR-DBC-02). - 5.1. This library (ConnectionClient.Setup) itself constructs neither aUrinor aClientInfo; it only callsIHttpJsonClient.SetClientInfowith the four string arguments. When the standardHttpJsonClientimplementation is registered, that call first constructs and assigns a newClientInfofrom the three identity arguments — throwing immediately on a null identity argument — and only after that succeeds constructs and assigns a newUrifromServiceUrl, throwing immediately on an invalidServiceUrl; the two assignments are not atomic, so a failingServiceUrlcan still leave the newly constructedClientInfoapplied to the instance.Origin: Step 5.1 is implemented in Initialize client (
SAIF.NetCore.HttpClients) when the standardHttpJsonClientimplementation is registered, and executed on behalf of this operation. 6. Enable NTLM authentication using the current process identity:SetNtlmAuthentication()with no arguments (BR-DBC-03). - 6.1. This library calls onlyIHttpJsonClient.SetNtlmAuthentication()with no arguments; when the standardHttpJsonClientimplementation is registered, that call builds a parameterlessNtlmAuthenticator(current process identity) and stores it on the client instance as_authenticator. The stored authenticator is only assigned to aRestClientlater, insideCreateClient, each time that implementation builds a newRestClientfor an outbound request — not at the timeSetNtlmAuthenticationis called. A differently registeredIHttpJsonClientimplementation is not required to construct anNtlmAuthenticatoror assign it the same way.Origin: Step 6.1 is implemented in Configure authentication (
SAIF.NetCore.HttpClients) when the standardHttpJsonClientimplementation is registered, and executed on behalf of this operation. - On failure: any exception raised by the environment client or HTTP client during steps 3–6 propagates out of the constructor uncaught; there is no error handling inSetup.
Process flow¶
flowchart TD
Start([Constructor invoked]) --> Init[Initialize cache and store dependencies]
Init --> Setup[Call Setup]
Setup --> ReadUrl["Read ServiceUrl, endpoint segments"]
ReadUrl --> ClientInfo["SetClientInfo: base URL + identity headers"]
ClientInfo --> Ntlm["SetNtlmAuthentication: current process identity"]
Ntlm --> Done([Configured instance ready])
Failure and edge-case behavior¶
- Any exception thrown by
IEnvironmentClientorIHttpJsonClientduringSetup()propagates out of the constructor; the caller receives a failed construction, not a partially configured instance. - Because
Setup()isvirtualand called from the constructor, a subclass override runs before the subclass's own constructor body completes*.
Related documentation¶
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
src/SAIF.NetCore.DbConnectionClient/SAIF.NetCore.DBConnectionClient/SAIF.NetCore.DBConnectionClient/ConnectionClient.cssrc/SAIF.NetCore.EnvironmentClient/SAIF.NetCore.EnvironmentClient/SAIF.NetCore.EnvironmentClient/BaseEnvironmentClient.cs(CheckForUpdates,LoadSection,HandleGetConfigurationSettingsResults,GetSettingFromDictionary— collaborator detail reached when the standardIEnvironmentClientimplementation is registered)src/SAIF.NetCore.HttpClients/SAIF.NetCore.HttpClients/SAIF.NetCore.HttpClients/HttpJsonClient/HttpJsonClient.cs(SetClientInfo,SetNtlmAuthentication,CreateClient— collaborator detail reached when the standardIHttpJsonClientimplementation is registered)