Class ServiceCollectionTransportExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Excalibur.Dispatch.dll
Extension methods for configuring transport bindings with IServiceCollection.
public static class ServiceCollectionTransportExtensions
- Inheritance
-
ServiceCollectionTransportExtensions
- Inherited Members
Methods
AddEventBindings(IServiceCollection, Action<ITransportBindingBuilder>)
Adds event binding configuration to the service collection.
public static IServiceCollection AddEventBindings(this IServiceCollection services, Action<ITransportBindingBuilder> configure)
Parameters
servicesIServiceCollectionThe service collection.
configureAction<ITransportBindingBuilder>Configuration action for bindings.
Returns
- IServiceCollection
The service collection for fluent configuration.
AddMultiTransportHealthChecks(IServiceCollection, Action<MultiTransportHealthCheckOptions>?, string, HealthStatus?, IEnumerable<string>?, TimeSpan?)
Adds multi-transport health checks to the service collection.
public static IServiceCollection AddMultiTransportHealthChecks(this IServiceCollection services, Action<MultiTransportHealthCheckOptions>? configure = null, string name = "transports", HealthStatus? failureStatus = null, IEnumerable<string>? tags = null, TimeSpan? timeout = null)
Parameters
servicesIServiceCollectionThe service collection.
configureAction<MultiTransportHealthCheckOptions>Optional configuration action for health check options.
namestringThe health check name. Default is "transports".
failureStatusHealthStatus?The failure status to report. Default is Unhealthy.
tagsIEnumerable<string>Optional tags for the health check. Default includes "transport" and "ready".
timeoutTimeSpan?Optional timeout for the health check.
Returns
- IServiceCollection
The service collection for fluent configuration.
Remarks
This health check monitors all transports registered in the ITransportRegistry. It reports the aggregate health status of all transports and provides detailed status for each individual transport in the health check data.
Usage example:
services.AddMultiTransportHealthChecks(opts =>
{
opts.RequireAtLeastOneTransport = true;
opts.RequireDefaultTransportHealthy = true;
});
AddTransportAdapterLifecycle(IServiceCollection, Action<TransportAdapterHostedServiceOptions>?)
Adds transport adapter lifecycle management as a hosted service.
public static IServiceCollection AddTransportAdapterLifecycle(this IServiceCollection services, Action<TransportAdapterHostedServiceOptions>? configure = null)
Parameters
servicesIServiceCollectionThe service collection.
configureAction<TransportAdapterHostedServiceOptions>Optional configuration action for hosted service options.
Returns
- IServiceCollection
The service collection for fluent configuration.
Remarks
This registers a hosted service that manages the lifecycle of transport adapters. Adapters are started when the application starts and gracefully stopped when the application shuts down, with a configurable drain timeout for pending messages.
Usage example:
services.AddTransportAdapterLifecycle(opts =>
{
opts.DrainTimeoutSeconds = 60;
opts.ThrowOnStartupFailure = true;
});
AddTransportValidation(IServiceCollection, Action<TransportValidationOptions>?)
Adds transport startup validation to the service collection.
public static IServiceCollection AddTransportValidation(this IServiceCollection services, Action<TransportValidationOptions>? configure = null)
Parameters
servicesIServiceCollectionThe service collection.
configureAction<TransportValidationOptions>Optional configuration action for validation options.
Returns
- IServiceCollection
The service collection for fluent configuration.
Remarks
This registers a hosted service that validates transport configuration at startup. Validation includes checking that a default transport is configured when multiple transports are registered.
GetOrCreateTransportRegistry(IServiceCollection)
Gets the existing ITransportRegistry from DI or creates and registers a new one.
public static ITransportRegistry GetOrCreateTransportRegistry(IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.
Returns
- ITransportRegistry
The singleton ITransportRegistry instance.
Remarks
This method is public to allow transport-specific packages to register their adapters with the shared ITransportRegistry. Using this method ensures that all transport adapters are managed by the same registry instance, enabling unified lifecycle management via TransportAdapterHostedService.
RequireAtLeastOneTransport(IServiceCollection)
Requires at least one transport to be registered, failing fast at startup otherwise. A discoverable
fluent shorthand for AddTransportValidation(o => o.RequireAtLeastOneTransport = true).
public static IServiceCollection RequireAtLeastOneTransport(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The service collection for fluent configuration.
Remarks
Named RequireAtLeastOneTransport (not RequireRemoteTransport) because the guarantee is
"one or more transports registered" — it does not distinguish local (in-memory) from remote transports.
Idempotent and order-independent: if transport validation was already added, this sets the flag on the
existing options; otherwise it registers validation with the flag enabled.