Path: redb-route/redb.Route.Xml/CoreElements/DeadLetterChannelContextContribution.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.Xml/CoreElements/DeadLetterChannelContextContribution.cs
----
using System.Xml.Linq;
using Microsoft.Extensions.Logging;
using redb.Route.Abstractions;
using redb.Route.ErrorHandling;
namespace redb.Route.Xml.CoreElements;
///
/// <deadLetterChannel uri="direct://errors"/> in context.xml: the context's dead letter channel
/// (), Apache Camel's errorHandlerRef on <camelContext>. Every route
/// of the context sends to it a failure no OnException took.
///
internal sealed class DeadLetterChannelContextContribution : IXmlContextContribution
{
/// The one instance, in the core registry.
internal static DeadLetterChannelContextContribution Instance { get; } = new();
// Not constructible from outside: a host that discovers package contributions by scanning assemblies for
// IXmlElementContribution types with a parameterless constructor (redb.Tsak) must not register a core element twice.
private DeadLetterChannelContextContribution() { }
///
public string Name => "deadLetterChannel";
///
public XmlElementKind Kind => XmlElementKind.ContextLevel;
///
public ElementSpec Spec => CoreContributions.Specs[Name];
///
public IRouteDefinition Apply(XElement element, IRouteDefinition current, XmlParseContext context)
{
context.AddError(element, " is the context's error handler — put it inside , not in a route.");
return current;
}
///
public void ApplyContext(XElement element, Core.RouteContext context, XmlParseContext parseContext)
{
if (parseContext.RequiredAttr(element, "uri") is not { } uri)
return;
if (context.ErrorHandler is not null)
{
parseContext.AddError(element,
"the context already has an error handler; would replace it — declare one of them.");
return;
}
context.ErrorHandler = new DeadLetterErrorHandler(context, uri,
context.GetService()?.CreateLogger());
}
}