Path: redb-route/redb.Route/Components/RegistryClaimCheckRepositoryProvider.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/Components/RegistryClaimCheckRepositoryProvider.cs
----
using redb.Route.Abstractions;
using redb.Route.Processors;
namespace redb.Route.Components;
///
/// Resolves instances for Claim Check steps. A named repository is found in the
/// registry by its bare name, checked for type (Camel's lookupByNameAndType), the
/// same key every other #name reference uses. The repository of steps that name none is the context's
/// service, looked up by type.
///
public static class ClaimCheckRepositoryRegistry
{
private static readonly object DefaultLock = new();
///
/// Registers an in the context registry under , so
/// route steps can refer to it as .ClaimCheck(operation, repositoryName: "large-payloads").
///
public static IRouteContext AddClaimCheckRepository(
this IRouteContext context, string name, IClaimCheckRepository repository)
{
ArgumentNullException.ThrowIfNull(context);
ArgumentException.ThrowIfNullOrEmpty(name);
ArgumentNullException.ThrowIfNull(repository);
context.AddToRegistry(RegistryLookup.Key(name), repository);
return context;
}
///
/// Registers the repository used by Claim Check steps that name none, as the context's
/// service. Without it the context falls back to a shared
/// .
///
public static IRouteContext SetDefaultClaimCheckRepository(
this IRouteContext context, IClaimCheckRepository repository)
{
ArgumentNullException.ThrowIfNull(context);
ArgumentNullException.ThrowIfNull(repository);
context.AddService(typeof(IClaimCheckRepository), repository);
return context;
}
///
/// Resolves the repository for a Claim Check step. A name is looked up in the registry; without one, the context's
/// service (, or one the host
/// registered), else a shared in-memory repository created once per context and kept as that service.
///
/// Route context being compiled.
/// Registry name, or null for the default.
/// A name was given and nothing, or an object of another type, is registered under it.
public static IClaimCheckRepository ResolveClaimCheckRepository(
this IRouteContext context, string? repositoryName = null)
{
ArgumentNullException.ThrowIfNull(context);
if (!string.IsNullOrEmpty(repositoryName))
{
var key = RegistryLookup.Key(repositoryName);
return RegistryLookup.Find(context, key)
?? throw new InvalidOperationException(
$"Nothing is registered under '{key}': register an IClaimCheckRepository with " +
$"context.AddClaimCheckRepository(\"{key}\", repository), or declare in Route-XML.");
}
var fromServices = context.GetService();
if (fromServices is not null)
return fromServices;
// The fallback must be shared across steps: a Set in one step and a Get in another
// have to reach the same store, otherwise the claim key resolves to nothing.
lock (DefaultLock)
{
var existing = context.GetService();
if (existing is not null)
return existing;
var created = new InMemoryClaimCheckRepository();
context.AddService(typeof(IClaimCheckRepository), created);
return created;
}
}
}