Path: redb-route/redb.Route/Components/RegistryIdempotentRepositoryProvider.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/RegistryIdempotentRepositoryProvider.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Components;
///
/// Default : resolves a repository from the
/// registry by its bare name, checked for type — Camel's lookupByNameAndType. The name is the registry key as
/// is, the same key every other #name reference uses, so a bean declared in markup under dedup is the
/// repository repository="#dedup" names.
///
public sealed class RegistryIdempotentRepositoryProvider : IIdempotentRepositoryProvider
{
private readonly IRouteContext _context;
/// Creates a provider backed by the given route context's registry.
public RegistryIdempotentRepositoryProvider(IRouteContext context)
{
ArgumentNullException.ThrowIfNull(context);
_context = context;
}
///
public IIdempotentRepository Get(string name)
{
ArgumentException.ThrowIfNullOrEmpty(name);
if (TryGet(name, out var repository))
return repository;
var key = RegistryLookup.Key(name);
throw new InvalidOperationException(
$"Nothing is registered under '{key}': register an IIdempotentRepository with " +
$"context.AddIdempotentRepository(\"{key}\", repository), or declare in Route-XML.");
}
///
/// Finds the repository registered under . false when nothing is registered there;
/// an object of another type under the name is a configuration error and throws.
///
public bool TryGet(string name, out IIdempotentRepository repository)
{
repository = null!;
if (string.IsNullOrEmpty(name)) return false;
var found = RegistryLookup.Find(_context, name);
if (found is null) return false;
repository = found;
return true;
}
}
/// A registry lookup by bare name, checked for type: nothing there, or the wrong type, are told apart.
internal static class RegistryLookup
{
/// The registry key of a reference: #name and name are the same key.
public static string Key(string name) => name.StartsWith('#') ? name[1..] : name;
/// The object under as ; null when nothing is there.
/// An object of another type is registered under the name.
public static T? Find(IRouteContext context, string name) where T : class
{
var key = Key(name);
var found = context.GetFromRegistry