Path: redb-route/redb.Route/Definitions/SetBodyDefinition.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/SetBodyDefinition.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Processors;
namespace redb.Route.Definitions;
///
/// Leaf definition that sets the exchange body to a static value.
///
public sealed class SetBodyStaticDefinition : ProcessorDefinition
{
private readonly object? _value;
/// Creates a set-body definition with a static value.
public SetBodyStaticDefinition(object? value) { _value = value; }
///
public override IProcessor CreateProcessor(IRouteContext context)
=> new DelegateProcessor(exchange => exchange.In.Body = _value);
}
///
/// Leaf definition that sets the exchange body using a factory function.
///
public sealed class SetBodyFactoryDefinition : ProcessorDefinition
{
private readonly Func _factory;
/// Creates a set-body definition using a factory.
public SetBodyFactoryDefinition(Func factory)
{
ArgumentNullException.ThrowIfNull(factory);
_factory = factory;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
=> new DelegateProcessor(exchange => exchange.In.Body = _factory(exchange));
}
///
/// Leaf definition that sets the exchange body using an .
///
public sealed class SetBodyExpressionDefinition : ProcessorDefinition
{
private readonly IExpression _expression;
/// The expression producing the body value.
public IExpression Expression => _expression;
/// Creates a set-body definition from an expression.
public SetBodyExpressionDefinition(IExpression expression)
{
ArgumentNullException.ThrowIfNull(expression);
_expression = expression;
}
///
public override IProcessor CreateProcessor(IRouteContext context)
=> new ExpressionBodyProcessor(_expression);
}