Skip to main content
Package: 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.
Then inject NexusClient anywhere:

Options

HttpClient and StreamHandler are deliberately absent. On this path the HTTP clients come from IHttpClientFactory, which is the point of using it - configure them by name instead.

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.
Do not “fix” this with SetHandlerLifetime(Timeout.InfiniteTimeSpan). That reintroduces exactly the stale-DNS problem the factory exists to solve: a process that never recycles a connection never observes an ingress reconfiguration or a load-balancer replacement.

Next