Path: redb-route/redb.Route.As4/As4Component.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.As4/As4Component.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Extensions;
using redb.Route.Http;
namespace redb.Route.As4;
///
/// AS4 (OASIS ebMS 3.0, AS4 profile; eDelivery AS4 1.16 common profile) transport component for redb.Route.
/// Schemes: as4 (HTTP) and as4s (HTTPS).
///
/// Receive: as4:/as4/in?host=0.0.0.0&port=4090&connectionFactory=node.
/// Send: as4s://ap.partner.example/as4?connectionFactory=node&partner=acme.
///
/// Consumer or producer is chosen by the DSL side (.From / .To). The node and its trading
/// partners are resolved from the registry when the endpoint starts — see .
///
public sealed class As4Component : ComponentBase
{
// Standalone fallback server, used only when no shared instance was injected (tests, or a host without
// AddRedbRouteHttpHosting).
private readonly Lazy _ownServer = new(() => new SharedHttpServerManager());
/// The shared Kestrel receive server, set by the DI registrar; owned by the container.
public SharedHttpServerManager? ServerManager { get; set; }
///
/// The server to host receive endpoints on: the DI-injected one; else the shared instance from the route
/// context's service provider (the path under Tsak, which loads connectors with
/// Activator.CreateInstance and injects nothing); else a private fallback.
///
internal SharedHttpServerManager Server =>
ServerManager
?? Context.Resolve()
?? _ownServer.Value;
///
public override string Scheme => "as4";
/// HTTPS variant of the AS4 scheme.
public override IReadOnlyList AlternateSchemes => ["as4s"];
///
public override IEndpoint CreateEndpoint(EndpointUri uri)
{
ArgumentNullException.ThrowIfNull(uri);
var options = new As4EndpointOptions();
options.BindFromUri(uri.RawParameters);
// The scheme carries the TLS decision: as4s means HTTPS. Applied after binding, before validation.
if (string.Equals(uri.Scheme, "as4s", StringComparison.OrdinalIgnoreCase))
options.UseTls = true;
options.Validate();
return new As4Endpoint(uri, this, options);
}
///
public override async ValueTask DisposeAsync()
{
// Only the private fallback is ours to dispose; a shared server belongs to the container.
if (_ownServer.IsValueCreated)
await _ownServer.Value.DisposeAsync().ConfigureAwait(false);
}
}