Transports & dispatchers
Transports & dispatchers in the .NET SDK.
| Symbol | Kind | Summary |
|---|---|---|
HttpClientTransport | class | The default transport, over HttpClient. |
INexusDispatcher | interface | Decides what actually happens when a resource method is called. |
INexusTransport | interface | Sends one HTTP request. |
NexusTransportResponse | class | A transport-level HTTP response, before any Nexus semantics. |
HttpClientTransport
classclass Inverge.Nexus.Transport.HttpClientTransportThe default transport, over HttpClient.
With no client supplied, every NexusClient in the process shares
one pooled HttpClient. That is the correct default for a library:
a client per instance exhausts sockets under load, and a client that lives
forever without a connection lifetime never notices a DNS change. On modern
targets the shared handler recycles connections every five minutes for exactly
that reason.
In an ASP.NET Core or worker app, prefer handing in a client from
IHttpClientFactory — services.AddNexus() does this — so the
app's own handler pipeline, resilience policies and DNS behaviour apply. An
injected client is owned by the caller and is never disposed here.
HttpClientTransport
constructornew HttpClientTransport()Uses the process-wide shared HttpClient.
HttpClientTransport
constructornew HttpClientTransport(HttpClient client)Uses a caller-supplied HttpClient, which it does not dispose.
Parameters
Prop
Type
Dispose()
methodvoid Dispose()SendAsync()
methodTask<NexusTransportResponse> SendAsync(string method, string url, IReadOnlyDictionary<string, string> headers, byte[]? body, TimeSpan timeout, CancellationToken cancellationToken)Parameters
Prop
Type
Returns Task<NexusTransportResponse>
INexusDispatcher
interfaceinterface Inverge.Nexus.Dispatch.INexusDispatcherDecides what actually happens when a resource method is called.
Implement this to hand delivery to your own infrastructure — a queue, a durable outbox, a hosted channel — so Nexus traffic inherits whatever reliability guarantees the rest of your system has.
DispatchAsync()
methodTask<JsonNode?> DispatchAsync(NexusRequest request, CancellationToken cancellationToken)Delivers a request. A dispatcher that does not deliver inline returns
null, so calls that need the response cannot be used with one.
Parameters
Prop
Type
Returns Task<JsonNode?>
FlushAsync()
methodTask FlushAsync(TimeSpan timeout, CancellationToken cancellationToken)Waits for in-flight deliveries. A no-op for a synchronous dispatcher.
Parameters
Prop
Type
StopAsync()
methodTask StopAsync(TimeSpan timeout)Releases resources, flushing first.
Parameters
Prop
Type
INexusTransport
interfaceinterface Inverge.Nexus.Transport.INexusTransportSends one HTTP request. Implement this to put the SDK's traffic through your own pipeline — a proxy, a recorded fixture, a test double.
An implementation should return a NexusTransportResponse for any
status the server actually produced, including 4xx and 5xx: turning those into
Nexus errors is the client's job, and it needs the server's own message to do
it. Throw NexusTransportException only for genuine
network-level failures.
SendAsync()
methodTask<NexusTransportResponse> SendAsync(string method, string url, IReadOnlyDictionary<string, string> headers, byte[]? body, TimeSpan timeout, CancellationToken cancellationToken)Sends the request and returns whatever the server answered.
Parameters
Prop
Type
Returns Task<NexusTransportResponse>
NexusTransportResponse
classclass Inverge.Nexus.Transport.NexusTransportResponseA transport-level HTTP response, before any Nexus semantics.
NexusTransportResponse
constructornew NexusTransportResponse(int status, byte[]? body = null, IReadOnlyDictionary<string, string>? headers = null)Creates a response.
Parameters
Prop
Type
Body
propertybyte[] Body { get; }The raw body bytes.
Headers
propertyIReadOnlyDictionary<string, string> Headers { get; }Response headers. Keys are compared case-insensitively.
IsSuccess
propertybool IsSuccess { get; }Whether the status is 2xx.
Status
propertyint Status { get; }The HTTP status code.
Text
propertystring Text { get; }The body decoded as UTF-8.
ReadJson()
methodJsonNode? ReadJson()The body parsed as JSON, or null when it is empty or not JSON.
A non-JSON body is a normal outcome — a proxy's HTML error page, a 204 —
so this returns null rather than throwing. The caller still has
Text for the error it reports.
Returns JsonNode?
