WestyxNexus.Extensions.DependencyInjection (v0.11.0+)
AddWestyxNexus() registers the client as a singleton, wires it through IHttpClientFactory and the application’s ILoggerFactory, and performs the initial sync during host startup.
NexusConfig - the same object
the configuration source takes - can be passed directly
instead of retyping its fields:
HttpClient, StreamHandler and PooledConnectionLifetime are rejected on this path rather than
ignored, naming the property: IHttpClientFactory owns all three here.
This registers a client of its own. If Nexus configs should reach IConfiguration as well, use
builder.AddWestyxNexus(config) - adding
builder.Configuration.AddWestyx(config) next to this call creates a second client, with its own
sync loop and its own SSE connection.
Then inject NexusClient anywhere:
Options
HttpClient, StreamHandler, LoggerFactory and Observer are deliberately absent from NexusOptions (since v0.17.0 for the latter two). HttpClient/StreamHandler come from IHttpClientFactory on this path - configure them by name instead. LoggerFactory and IStreamObserver are service references a configuration binder can never construct, so they are registered in the container instead and AddWestyxNexus resolves them from there:
WifOptions
NexusOptions.Wif is a WifOptions, the configuration-bindable form of
WifConfig:
WifOptions has no CredentialSource property - a credential source is a service reference, not a configuration value, so it is registered in the container instead. See Registering a credential source below.
aws_iam is not a Provider value - it is a credential source. Add WestyxNexus.Wif.Aws and call services.AddWestyxNexusAwsIam("eu-central-1"), which also takes the region; a configuration that names aws_iam throws at startup saying exactly that.
Provider is a string here while WifConfig.Provider is an enum, and that is deliberate - see
Design decisions.
Registering a credential source
A credential source registered in the container is picked up automatically, so nothing has to be set in code on the options:WifOptions has no property to set one directly. See Workload identity for the non-DI path, where WifConfig.CredentialSource is a settable property.
Startup is asynchronous
The initial sync is a network call. A plain singleton factory would have to block:AddWestyxNexus() instead starts the work once and awaits it in an IHostedService, so host startup stays properly asynchronous and a misconfiguration surfaces as a startup failure rather than as a failure on the first request.
The hosted service is inserted at the front of the service collection, so the client is ready before any hosted service you registered can resolve it.
Customising the HTTP clients
Two named clients are registered:
Add your own handlers, retry policies or timeouts to either:
Handler rotation is safe for SSE
IHttpClientFactory rotates handlers every two minutes, which looks fatal for a connection that stays open for hours. It is not: the factory only stops handing an expired handler to new requests - a request already in flight keeps its handler until it completes.
Next
- Secrets binding -
IOptions<T>for secrets - Feature management - Nexus flags through
IFeatureManager - ASP.NET Core configuration - configs through
IConfiguration - Design decisions
