Path: redb-route/redb.Route/Definitions/RouteConfigurationDefinition.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/Definitions/RouteConfigurationDefinition.cs
----
namespace redb.Route.Definitions;
///
/// A route configuration (Apache Camel's Route Configuration): error handling declared once, apart from the routes,
/// and applied to the routes of any builder of the context.
///
/// A configuration without an id is the default: it applies to every route that has no configurations assigned. A
/// configuration with an id applies to the routes that name it with .RouteConfigurationId("id").
///
/// Declared in a .
///
public sealed class RouteConfigurationDefinition
{
private readonly List _exceptionDefinitions = [];
internal RouteConfigurationDefinition(string? id)
{
if (id is not null)
ArgumentException.ThrowIfNullOrWhiteSpace(id);
Id = id;
}
/// The id routes name the configuration by; null for the default configuration.
public string? Id { get; }
/// The exception handlers of the configuration, in declaration order.
public IReadOnlyList ExceptionDefinitions => _exceptionDefinitions;
///
/// Defines an exception handler of the configuration: every setting and every step an OnException of a
/// builder has (redeliveries, OnWhen, Handled, the handler's steps). For a failure of a route the
/// handler nearest to the exception type wins, wherever it is declared; the route's own handler wins a tie, and
/// the configuration's handler is used instead of a handler of the same type on the route's builder.
///
/// Exception type to handle.
/// Definition for fluent chaining of handler steps and configuration.
public OnExceptionDefinition OnException() where TException : Exception
=> OnException(typeof(TException));
/// Defines an exception handler of the configuration for several exception types at once.
/// Exception types to handle.
/// Definition for fluent chaining.
public OnExceptionDefinition OnException(params Type[] exceptionTypes)
{
if (exceptionTypes is not { Length: > 0 })
throw new ArgumentException("At least one exception type must be specified.", nameof(exceptionTypes));
foreach (var t in exceptionTypes)
if (!typeof(Exception).IsAssignableFrom(t))
throw new ArgumentException($"Type '{t.Name}' is not an Exception type.", nameof(exceptionTypes));
var def = new OnExceptionDefinition(exceptionTypes);
_exceptionDefinitions.Add(def);
return def;
}
}