Path: redb-route/redb.Route/Expressions/RegistryRefSite.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/Expressions/RegistryRefSite.cs
----
using System.Runtime.CompilerServices;
using redb.Route.Abstractions;
namespace redb.Route.Expressions;
///
/// One ref:name in a compiled expression: the object registered under that name. The expression is compiled
/// once and shared by every context, so the object is looked up per route context, on the first evaluation there, as
/// a bean: call resolves its bean (). A weak table keeps no context alive. Refused
/// under , as bean: is.
///
internal sealed class RegistryRefSite(string reference)
{
private readonly ConditionalWeakTable _resolved = new();
/// The registered object.
public object Get(IExchange exchange)
{
var context = exchange.Context ?? throw new InvalidOperationException(
$"ref:{reference}: the exchange has no route context, so there is no registry to find the object in.");
if (ExpressionSandbox.IsActive)
throw new ExpressionSandboxViolationException("ref:" + reference);
return _resolved.GetValue(context, Resolve);
}
private object Resolve(IRouteContext context)
=> context.GetFromRegistry