Path: redb/redb.Core/RedbServiceBase.cs
Snapshot: redb, 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
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/RedbServiceBase.cs
----
#pragma warning disable CS0618 // implements or uses the deprecated object permissions and roles (RedbDeprecation)
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using redb.Core.Caching;
using redb.Core.Data;
using redb.Core.Providers;
using redb.Core.Query;
using redb.Core.Serialization;
using redb.Core.Utils;
using redb.Core.Models.Enums;
using redb.Core.Models.Permissions;
using redb.Core.Models.Contracts;
using redb.Core.Models.Security;
using redb.Core.Models.Entities;
using redb.Core.Models.Configuration;
using redb.Core.Attributes;
using redb.Core.Exceptions;
using redb.Core.Models;
using redb.Core.Services;
using System.Reflection;
using System.Threading;
using System.Runtime.Loader;
namespace redb.Core;
///
/// Base abstract class for RedbService implementations.
/// Contains all common logic for delegating to providers.
/// Provider-specific implementations (Postgres, MSSQL) inherit from this class.
///
public abstract partial class RedbServiceBase : IRedbService
{
private readonly IRedbContext _context;
private readonly ISchemeSyncProvider _schemeSync;
protected IObjectStorageProvider _objectStorage;
protected ITreeProvider _treeProvider;
private readonly IPermissionProvider _permissionProvider;
protected IQueryableProvider _queryProvider;
// The query provider every query goes through. The groupings of its queries read their list item keys through
// the list provider (Query.Grouping.ListItemGroupKeys): it is handed over here, on use, because a Pro service
// replaces _queryProvider after this constructor. An implementation not derived from QueryableProviderBase has
// none, and such a grouping refuses with the reason.
private IQueryableProvider Queries
{
get
{
if (_queryProvider is Providers.Base.QueryableProviderBase queryables && queryables.ListItems == null)
queryables.ListItems = _listProvider;
return _queryProvider;
}
}
private readonly IValidationProvider _validationProvider;
private readonly IRedbSecurityContext _securityContext;
private readonly IUserProvider _userProvider;
private readonly IRoleProvider _roleProvider;
private readonly IListProvider _listProvider;
private readonly IServiceProvider _serviceProvider;
// readonly: the providers hold this instance, so it is only ever changed in place (UpdateConfiguration).
private readonly RedbServiceConfiguration _configuration;
private readonly IRedbObjectSerializer _serializer;
private readonly ILogger? _logger;
///
/// Cache domain identifier for isolating caches between different database connections.
///
protected readonly string _cacheDomain;
///
/// Database context for direct data access.
///
public IRedbContext Context => _context;
public IRedbSecurityContext SecurityContext => _securityContext;
public IUserProvider UserProvider => _userProvider;
public IRoleProvider RoleProvider => _roleProvider;
public IListProvider ListProvider => _listProvider;
public RedbServiceConfiguration Configuration => _configuration;
///
/// Cache domain identifier for this service instance.
///
public string CacheDomain => _cacheDomain;
// === ABSTRACT METHODS FOR PROVIDER-SPECIFIC IMPLEMENTATIONS ===
///
/// Database provider name (e.g., "PostgreSQL", "MSSql").
///
protected abstract string DatabaseTypeName { get; }
///
/// SQL query to get database version.
///
protected abstract string GetVersionSql { get; }
///
/// SQL query to get database size in bytes.
///
protected abstract string GetDatabaseSizeSql { get; }
///
/// Error message when IRedbContext is not registered.
///
protected abstract string ContextNotRegisteredError { get; }
///
/// Create scheme sync provider.
///
protected abstract ISchemeSyncProvider CreateSchemeSyncProvider(
IRedbContext context, RedbServiceConfiguration config, string cacheDomain, ILogger? logger);
///
/// Create permission provider.
///
protected abstract IPermissionProvider CreatePermissionProvider(
IRedbContext context, IRedbSecurityContext securityContext, ILogger? logger);
///
/// Create user provider.
///
protected abstract IUserProvider CreateUserProvider(
IRedbContext context, IRedbSecurityContext securityContext, ILogger? logger);
///
/// Create role provider.
///
protected abstract IRoleProvider CreateRoleProvider(
IRedbContext context, IRedbSecurityContext securityContext, ILogger? logger);
///
/// Create list provider.
///
protected abstract IListProvider CreateListProvider(
IRedbContext context, RedbServiceConfiguration config, ISchemeSyncProvider schemeSync, ILogger? logger);
///
/// Save-pipeline interceptors (discussion #12) handed to the storage provider: the DI registrations, resolved
/// once, and the run-time subscriptions of the , read on
/// every save. Pro services building their own storage call this too.
///
protected Interception.RedbSaveInterceptorPipeline ResolveSaveInterceptors()
=> new(
_serviceProvider.GetService(typeof(IEnumerable))
as IEnumerable,
_serviceProvider.GetService(typeof(Interception.IRedbSaveInterceptorRegistry))
as Interception.IRedbSaveInterceptorRegistry);
///
/// Password hasher for the user provider: a DI registration wins, the fallback is bcrypt.
/// Never SimplePasswordHasher - a bare redb deployment must not default to salted SHA256
/// (external security report, 2026-09-08). Legacy SHA256+salt hashes keep validating:
/// BcryptPasswordHasher recognizes both formats.
///
protected Security.IPasswordHasher ResolvePasswordHasher()
=> _serviceProvider.GetService(typeof(Security.IPasswordHasher)) as Security.IPasswordHasher
?? new Security.BcryptPasswordHasher();
///
/// Create object storage provider.
///
protected abstract IObjectStorageProvider CreateObjectStorageProvider(
IRedbContext context, IRedbObjectSerializer serializer, IPermissionProvider permissionProvider,
IRedbSecurityContext securityContext, ISchemeSyncProvider schemeSync,
RedbServiceConfiguration config, IListProvider listProvider, ILogger? logger,
Interception.RedbSaveInterceptorPipeline? saveInterceptors);
///
/// Create tree provider.
///
protected abstract ITreeProvider CreateTreeProvider(
IRedbContext context, IObjectStorageProvider objectStorage, IPermissionProvider permissionProvider,
IRedbObjectSerializer serializer, IRedbSecurityContext securityContext,
ISchemeSyncProvider schemeSync, RedbServiceConfiguration config, ILogger? logger,
Interception.RedbSaveInterceptorPipeline? saveInterceptors);
///
/// Create lazy props loader.
///
protected abstract ILazyPropsLoader CreateLazyPropsLoader(
IRedbContext context, ISchemeSyncProvider schemeSync, IRedbObjectSerializer serializer,
RedbServiceConfiguration config, string cacheDomain, IListProvider listProvider, ILogger? logger);
///
/// Create queryable provider.
///
protected abstract IQueryableProvider CreateQueryableProvider(
IRedbContext context, IRedbObjectSerializer serializer, ISchemeSyncProvider schemeSync,
IRedbSecurityContext securityContext, ILazyPropsLoader lazyPropsLoader,
RedbServiceConfiguration config, string cacheDomain, ILogger? logger);
///
/// Create validation provider.
///
protected abstract IValidationProvider CreateValidationProvider(
IRedbContext context, ILogger? logger);
///
/// Factory for the maintenance provider (planner statistics, index health). Lazy: most
/// scopes never touch maintenance, so nothing is built until the first access.
///
protected abstract IMaintenanceProvider CreateMaintenanceProvider(
IRedbContext context, int analysisLimit, ILogger? logger);
private IMaintenanceProvider? _maintenance;
///
public IMaintenanceProvider Maintenance
=> _maintenance ??= CreateMaintenanceProvider(_context, _configuration.MaintenanceAnalysisLimit, _logger);
///
/// SQL dialect for database-specific queries.
///
protected abstract ISqlDialect SqlDialect { get; }
///
/// Initialize RedbServiceBase with dependency injection.
///
protected RedbServiceBase(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
_context = serviceProvider.GetService() ??
throw new InvalidOperationException(ContextNotRegisteredError);
_serializer = serviceProvider.GetService() ?? new SystemTextJsonRedbSerializer();
_logger = serviceProvider.GetService>() as ILogger;
// Process-wide caches forget a collectible AssemblyLoadContext (a module) when it unloads.
Caching.CollectibleContextCleanup.EnsureWatching(_logger);
_configuration = serviceProvider.GetService() ?? new RedbServiceConfiguration();
_securityContext = serviceProvider.GetService() ??
AmbientSecurityContext.GetOrCreateDefault();
// Compute cache domain for this service instance
_cacheDomain = _configuration.GetEffectiveCacheDomain();
// Create providers using abstract factory methods (passing cacheDomain)
_schemeSync = CreateSchemeSyncProvider(_context, _configuration, _cacheDomain, _logger);
// A scheme sync that has to write takes the schema lock of this service (see SchemeSyncProviderBase).
if (_schemeSync is Providers.Base.SchemeSyncProviderBase schemeSyncBase)
{
schemeSyncBase.RunUnderSchemaLock = RunUnderSchemaLockAsync;
schemeSyncBase.SchemaProblemFound = ReportSchemaProblem;
}
_permissionProvider =CreatePermissionProvider(_context, _securityContext, _logger);
// Permission cache keys carry the database: ids are per database (review 2026-09-24, C-1).
if (_permissionProvider is Providers.Base.PermissionProviderBase permissionBase)
permissionBase.CacheDomain = _cacheDomain;
_userProvider = CreateUserProvider(_context, _securityContext, _logger);
_roleProvider = CreateRoleProvider(_context, _securityContext, _logger);
_listProvider = CreateListProvider(_context, _configuration, _schemeSync, _logger);
// One interceptor pipeline for the storage and the tree: DeleteSubtreeAsync fires the delete interceptors too.
var saveInterceptors = ResolveSaveInterceptors();
_objectStorage = CreateObjectStorageProvider(_context, _serializer, _permissionProvider,
_securityContext, _schemeSync, _configuration, _listProvider, _logger,
saveInterceptors);
_treeProvider = CreateTreeProvider(_context, _objectStorage, _permissionProvider,
_serializer, _securityContext, _schemeSync, _configuration, _logger, saveInterceptors);
// A data object owns no connection: RedbListItem.Object and the Props of reference stubs load on the live
// scope of whoever reads them. This service becomes current for the flow that resolved it, and registers its
// database for the loads that find no live scope (refused by default, a fresh scope by explicit option). The
// per-item and process-wide loader delegates it installed before opened a fresh scope and pooled connection per
// read.
_listProvider.LinkedObjectsBatchLoader = LoadLinkedObjectsBatchAsync;
ScopeFactory = serviceProvider.GetService();
RedbDomainRegistry.Register(_cacheDomain, ScopeFactory, _configuration, _logger);
// A service of the root provider is captive: it lives as long as the process, and the frame it enters below is
// inherited by every flow. It lends lazy loads its scope factory, never its one connection (RedbDomainRegistry.
// InScopeOf) - parallel lazy loads of shared instances collided on that connection (review after 4.0.0).
IsCaptive = ScopeFactory != null && RedbServiceProviders.IsRoot(serviceProvider);
LazyPropsLoader = CreateLazyPropsLoader(_context, _schemeSync, _serializer,
_configuration, _cacheDomain, _listProvider, _logger);
_queryProvider = CreateQueryableProvider(_context, _serializer, _schemeSync,
_securityContext, LazyPropsLoader, _configuration, _cacheDomain, _logger);
_validationProvider = CreateValidationProvider(_context, _logger);
SelfReference = new WeakReference(this);
ServicesByContext.AddOrUpdate(_context, this);
RedbAmbientScope.Enter(this);
}
// === Lazy loads on the reader's scope ===
// Context (one scope, one connection) -> the service of that scope: how a scope-bound loader names the origin of the
// instances it materializes. Weak both ways: an ended scope leaves nothing behind.
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable ServicesByContext = new();
/// The service whose scope owns ; null for an unknown context.
internal static RedbServiceBase? ServiceOf(IRedbContext? context)
=> context != null && ServicesByContext.TryGetValue(context, out var service) ? service : null;
/// A weak reference to this service, shared by every instance it is the origin of.
internal WeakReference SelfReference { get; }
///
/// This service's own lazy Props loader, bound to its context. Reference stubs never carry it: they carry the
/// scope-free loader of this database, which calls the loader of whichever live service reads them.
///
protected internal ILazyPropsLoader LazyPropsLoader { get; protected set; } = null!;
/// Whether this service's scope has ended (its context is disposed): it no longer answers lazy loads.
internal bool IsScopeEnded => _context.IsDisposed;
/// The service was resolved from the root provider of its container (see ).
internal bool IsCaptive { get; }
///
/// Whether a lazy load resolved to this reader runs in a fresh scope of its container instead of on its connection: a
/// captive service outside a transaction. Inside its transaction the connection is the transaction, and the load is
/// part of it - it reads what the transaction wrote, as it did before.
///
internal bool LendsScope => IsCaptive && !_context.IsInTransaction;
/// The logger of this service; null when the host registered none.
protected internal ILogger? Logger => _logger;
/// The scope factory of the container that resolved this service; null outside DI.
internal IServiceScopeFactory? ScopeFactory { get; }
///
/// The captive service this scope was lent to for one load (); null for a
/// scope of its own.
///
internal RedbServiceBase? LentTo { get; set; }
///
/// The service that instances materialized by this one name as their origin: itself, or the captive service it was lent
/// to. A lent scope ends with its load, while what it loaded lives on with the captive reader - the stubs under it
/// load through a lent scope of their own.
///
internal RedbServiceBase AsOrigin => LentTo ?? this;
// === A scope of this service's container (IRedbScopeSource) ===
///
public bool CanCreateScope => ScopeFactory != null;
///
public RedbScope CreateScope()
{
if (ScopeFactory == null)
throw new InvalidOperationException(
"This IRedbService was built without a DI container (its provider has no IServiceScopeFactory), so it " +
"cannot open a scope of its own. Resolve services from a container to get one per unit of work.");
var scope = ScopeFactory.CreateAsyncScope();
RedbScope? opened = null;
try
{
var service = scope.ServiceProvider.GetRequiredService();
if (!string.Equals(service.CacheDomain, CacheDomain, StringComparison.Ordinal))
throw new InvalidOperationException(
$"A scope of this service's container resolves IRedbService for database '{service.CacheDomain}', not " +
$"'{CacheDomain}': the container registers IRedbService differently per resolution. A scope opened from " +
"a service must read that service's database; register one IRedbService per container.");
opened = new RedbScope(service, scope);
return opened;
}
finally
{
if (opened == null)
scope.Dispose();
}
}
///
public IDisposable BeginAccess() => RedbAmbientScope.Push(this);
///
public virtual IDisposable WithQueryPlanner(bool enabled) => redb.Core.Query.QueryPlannerScope.Unchanged;
/// Opens a query planner block for the calling flow; the tiers that have a planner return it from .
protected static IDisposable PushQueryPlanner(bool enabled) => redb.Core.Query.QueryPlannerScope.Push(enabled);
///
public async Task> LoadLinkedObjectsAsync(
IEnumerable items, CancellationToken cancellationToken = default)
{
var pending = items.Where(i => !i.IsObjectLoaded && i.IdObject.HasValue).ToList();
if (pending.Count == 0)
return new Dictionary();
var byId = await LoadLinkedObjectsBatchAsync(pending.Select(i => i.IdObject!.Value).Distinct().ToList(), cancellationToken);
foreach (var item in pending)
if (byId.TryGetValue(item.IdObject!.Value, out var obj))
item.Publish(obj, _context);
return byId;
}
///
/// Batch resolver behind the list hand-out preload: one polymorphic load for all linked
/// objects of a list. Depth 10 - the SAME depth the lazy getter path uses (LoadTypedAsync),
/// so a preloaded extension object is indistinguishable from a lazily loaded one (dictionary
/// extension objects are used actively and may carry nested references). Missing ids are
/// simply absent from the result - their items keep the lazy path.
///
private async Task> LoadLinkedObjectsBatchAsync(
IReadOnlyCollection objectIds, CancellationToken cancellationToken)
{
var loaded = await _objectStorage.LoadAsync(objectIds, depth: 10, cancellationToken: cancellationToken);
var byId = new Dictionary(loaded.Count);
foreach (var obj in loaded)
byId[obj.Id] = obj;
return byId;
}
///
/// The object behind a list item, loaded on this service's connection - the scope of whoever reads the item. A scope
/// that tears down meanwhile refuses the command (ObjectDisposedException); nothing falls back to another scope.
///
internal Task LoadLinkedObjectAsync(long objectId, CancellationToken cancellationToken)
=> LoadLinkedObjectCoreAsync(this, objectId, cancellationToken);
private static async Task LoadLinkedObjectCoreAsync(IRedbService service, long objectId, CancellationToken cancellationToken)
{
var dialect = (service as RedbServiceBase)?.SqlDialect;
var schemeId = dialect != null
? await service.Context.ExecuteScalarAsync(
dialect.ObjectStorage_SelectSchemeIdByObjectId(), new object[] { objectId }, cancellationToken)
: 0;
if (schemeId == 0)
return null;
// A scheme this node has never cached (a fresh process, another cluster node) is resolved by
// its id; the cache-only lookup fell through to the untyped get_object_json path below.
var propsType = await service.Cache.ResolveClrTypeAsync(schemeId, service);
if (propsType != null)
{
// The generic method is our own, so its shape is under our control: the previous
// lookup of IObjectStorageProvider.LoadAsync by parameter list silently returned null
// (NRE at runtime) the moment that signature grew a CancellationToken.
var load = typeof(RedbServiceBase)
.GetMethod(nameof(LoadTypedAsync), BindingFlags.NonPublic | BindingFlags.Static)!
.MakeGenericMethod(propsType);
return await (Task)load.Invoke(null, new object[] { service, objectId, cancellationToken })!;
}
if (service is not RedbServiceBase typed)
return null;
var json = await service.Context.ExecuteJsonAsync(
typed.SqlDialect.ObjectStorage_GetObjectJson(), new object[] { objectId, 10 }, cancellationToken);
return string.IsNullOrEmpty(json) ? null : typed._serializer.DeserializeDynamic(json, typeof(object));
}
private static async Task LoadTypedAsync(IObjectStorageProvider storage, long objectId, CancellationToken cancellationToken)
where TProps : class, new()
=> await storage.LoadAsync(objectId, 10, cancellationToken);
// === Synchronous twins (thread-pool-free lazy path) ===
// The sync getter of RedbListItem.Object prefers these: the whole load - scheme lookup,
// permission check, get_object_json, deserialization - runs on the calling thread down to
// ADO.NET, so a saturated thread pool cannot slow or deadlock a touch of Object. Mirrors of
// the async chain above, same depth, same diagnostics.
/// Synchronous twin of , on the calling thread down to ADO.NET.
internal IRedbObject? LoadLinkedObjectSync(long objectId) => LoadLinkedObjectCoreSync(this, objectId);
private static IRedbObject? LoadLinkedObjectCoreSync(IRedbService service, long objectId)
{
var dialect = (service as RedbServiceBase)?.SqlDialect;
var schemeId = dialect != null
? service.Context.ExecuteScalar(dialect.ObjectStorage_SelectSchemeIdByObjectId(), objectId)
: 0;
if (schemeId == 0)
return null;
// Same cold resolution as the async twin, on the calling thread.
var propsType = service.Cache.ResolveClrType(schemeId, service);
if (propsType != null)
{
// Same reflection shape as the async twin (and the same lesson: our own method, found
// by name, never by parameter list).
var load = typeof(RedbServiceBase)
.GetMethod(nameof(LoadTypedSync), BindingFlags.NonPublic | BindingFlags.Static)!
.MakeGenericMethod(propsType);
return (IRedbObject?)load.Invoke(null, new object[] { service, objectId });
}
if (service is not RedbServiceBase typed)
return null;
var json = service.Context.ExecuteJson(typed.SqlDialect.ObjectStorage_GetObjectJson(), objectId, 10);
return string.IsNullOrEmpty(json) ? null : typed._serializer.DeserializeDynamic(json, typeof(object));
}
private static IRedbObject? LoadTypedSync(IObjectStorageProvider storage, long objectId)
where TProps : class, new()
=> storage.Load(objectId, 10);
///
/// Get tree provider for extended scenarios.
///
public ITreeProvider GetTreeProvider() => _treeProvider;
// === DATABASE METADATA ===
// Sync properties ride the true sync path (calling thread down to ADO.NET) - the previous
// .Result over the async form parked a thread on pool-scheduled continuations (debug-era
// leftover; same class as the lazy-getter fix).
public string dbVersion => _context.ExecuteScalar(GetVersionSql) ?? "unknown";
public string dbType => DatabaseTypeName;
public string dbMigration => "ADO.NET";
public long? dbSize => _context.ExecuteScalar(GetDatabaseSizeSql);
///
public Task GetDbVersionAsync(CancellationToken cancellationToken = default)
=> _context.ExecuteScalarAsync(GetVersionSql);
// === ISchemeSyncProvider DELEGATION ===
public Task EnsureSchemeFromTypeAsync(CancellationToken cancellationToken = default) where TProps : class
=> _schemeSync.EnsureSchemeFromTypeAsync(cancellationToken);
public Task> SyncStructuresFromTypeAsync(IRedbScheme scheme, bool strictDeleteExtra = true, CancellationToken cancellationToken = default) where TProps : class
=> _schemeSync.SyncStructuresFromTypeAsync(scheme, strictDeleteExtra, cancellationToken);
public Task SyncSchemeAsync(CancellationToken cancellationToken = default) where TProps : class
=> _schemeSync.SyncSchemeAsync(cancellationToken);
///
public Task DropUnknownStructuresAsync(bool dryRun = true, CancellationToken cancellationToken = default)
where TProps : class
=> _schemeSync.DropUnknownStructuresAsync(dryRun, cancellationToken);
public Task GetSchemeByTypeAsync(CancellationToken cancellationToken = default) where TProps : class
=> _schemeSync.GetSchemeByTypeAsync(cancellationToken);
public Task GetSchemeByTypeAsync(Type type, CancellationToken cancellationToken = default)
=> _schemeSync.GetSchemeByTypeAsync(type, cancellationToken);
public IRedbScheme? GetSchemeFromCache() where TProps : class
=> _schemeSync.GetSchemeFromCache();
public IRedbScheme? GetSchemeFromCache(string schemeName)
=> _schemeSync.GetSchemeFromCache(schemeName);
public Task LoadSchemeByTypeAsync(CancellationToken cancellationToken = default) where TProps : class
=> _schemeSync.LoadSchemeByTypeAsync(cancellationToken);
public Task LoadSchemeByTypeAsync(Type type, CancellationToken cancellationToken = default)
=> _schemeSync.LoadSchemeByTypeAsync(type, cancellationToken);
public Task> GetStructuresByTypeAsync(CancellationToken cancellationToken = default) where TProps : class
=> _schemeSync.GetStructuresByTypeAsync(cancellationToken);
public Task> GetStructuresByTypeAsync(Type type, CancellationToken cancellationToken = default)
=> _schemeSync.GetStructuresByTypeAsync(type, cancellationToken);
public Task SchemeExistsForTypeAsync(CancellationToken cancellationToken = default) where TProps : class
=> _schemeSync.SchemeExistsForTypeAsync(cancellationToken);
public Task SchemeExistsForTypeAsync(Type type, CancellationToken cancellationToken = default)
=> _schemeSync.SchemeExistsForTypeAsync(type, cancellationToken);
public Task SchemeExistsByNameAsync(string schemeName, CancellationToken cancellationToken = default)
=> _schemeSync.SchemeExistsByNameAsync(schemeName, cancellationToken);
public string GetSchemeNameForType() where TProps : class
=> _schemeSync.GetSchemeNameForType();
public string GetSchemeNameForType(Type type)
=> _schemeSync.GetSchemeNameForType(type);
public string? GetSchemeAliasForType() where TProps : class
=> _schemeSync.GetSchemeAliasForType();
public string? GetSchemeAliasForType(Type type)
=> _schemeSync.GetSchemeAliasForType(type);
public Task GetSchemeByIdAsync(long schemeId, CancellationToken cancellationToken = default)
=> _schemeSync.GetSchemeByIdAsync(schemeId, cancellationToken);
public IRedbScheme? GetSchemeById(long schemeId)
=> _schemeSync.GetSchemeById(schemeId);
public Task GetSchemeByNameAsync(string schemeName, CancellationToken cancellationToken = default)
=> _schemeSync.GetSchemeByNameAsync(schemeName, cancellationToken);
public Task EnsureObjectSchemeAsync(string name, CancellationToken cancellationToken = default)
=> _schemeSync.EnsureObjectSchemeAsync(name, cancellationToken);
public Task GetObjectSchemeAsync(string name, CancellationToken cancellationToken = default)
=> _schemeSync.GetObjectSchemeAsync(name, cancellationToken);
public Task> GetSchemesAsync(CancellationToken cancellationToken = default)
=> _schemeSync.GetSchemesAsync(cancellationToken);
public GlobalMetadataCache Cache => _schemeSync.Cache;
public GlobalListCache ListCache => _schemeSync.ListCache;
public GlobalPropsCache PropsCache => _schemeSync.PropsCache;
public Task> GetStructuresAsync(IRedbScheme scheme, CancellationToken cancellationToken = default)
=> _schemeSync.GetStructuresAsync(scheme, cancellationToken);
public Task MigrateStructureTypeAsync(long structureId, string oldTypeName, string newTypeName, bool dryRun = false, CancellationToken cancellationToken = default)
=> _schemeSync.MigrateStructureTypeAsync(structureId, oldTypeName, newTypeName, dryRun, cancellationToken);
public Task RecomputeUniqueAsync(string propertyName, CancellationToken cancellationToken = default) where TProps : class
=> _schemeSync.RecomputeUniqueAsync(propertyName, cancellationToken);
public Task> GetStructureTreeAsync(long schemeId, CancellationToken cancellationToken = default)
=> _schemeSync.GetStructureTreeAsync(schemeId, cancellationToken);
public Task> GetSubtreeAsync(long schemeId, long? parentStructureId, CancellationToken cancellationToken = default)
=> _schemeSync.GetSubtreeAsync(schemeId, parentStructureId, cancellationToken);
public void InvalidateStructureTreeCache(long schemeId)
=> _schemeSync.InvalidateStructureTreeCache(schemeId);
public (int TreesCount, int SubtreesCount, long MemoryEstimate) GetStructureTreeCacheStats()
=> _schemeSync.GetStructureTreeCacheStats();
// === IObjectStorageProvider DELEGATION ===
public Task?> LoadAsync(long objectId, int depth = 10, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.LoadAsync(objectId, depth, cancellationToken);
// Without this delegation the facade would satisfy IObjectStorageProvider.Load with the
// interface DEFAULT - the blocking-over-async fallback - and the sync lazy path would quietly
// lose its thread-pool freedom (caught by the starvation stand: 4 capped threads, total
// freeze inside ConfiguredTaskAwaiter.GetResult under IObjectStorageProvider.Load).
public RedbObject? Load(long objectId, int depth = 10) where TProps : class, new()
=> _objectStorage.Load(objectId, depth);
public Task?> GetByUniqueAsync(System.Linq.Expressions.Expression> keyProperty, object? value, int depth = 10, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.GetByUniqueAsync(keyProperty, value, depth, cancellationToken);
public Task?> GetByUniqueAsync(string propertyName, object? value, int depth = 10, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.GetByUniqueAsync(propertyName, value, depth, cancellationToken);
public Task SaveByUniqueAsync(RedbObject obj, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.SaveByUniqueAsync(obj, cancellationToken);
public Task?> LoadAsync(IRedbObject obj, int depth = 10, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.LoadAsync(obj, depth, cancellationToken);
public Task?> LoadAsync(IRedbObject obj, IRedbUser user, int depth = 10, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.LoadAsync(obj, user, depth, cancellationToken);
public Task SaveAsync(IRedbObject obj, CancellationToken cancellationToken = default)
=> _objectStorage.SaveAsync(obj, cancellationToken);
public Task SaveAsync(IRedbObject obj, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.SaveAsync(obj, cancellationToken);
public Task DeleteAsync(IRedbObject obj, CancellationToken cancellationToken = default)
=> _objectStorage.DeleteAsync(obj, cancellationToken);
public Task?> LoadAsync(long objectId, IRedbUser user, int depth = 10, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.LoadAsync(objectId, user, depth, cancellationToken);
public Task LoadJsonAsync(long objectId, int depth = 10, CancellationToken cancellationToken = default)
=> _objectStorage.LoadJsonAsync(objectId, depth, cancellationToken);
public Task LoadJsonAsync(long objectId, IRedbUser user, int depth = 10, CancellationToken cancellationToken = default)
=> _objectStorage.LoadJsonAsync(objectId, user, depth, cancellationToken);
public Task SaveAsync(IRedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _objectStorage.SaveAsync(obj, user, cancellationToken);
public Task SaveAsync(IRedbObject obj, IRedbUser user, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.SaveAsync(obj, user, cancellationToken);
public Task DeleteAsync(IRedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _objectStorage.DeleteAsync(obj, user, cancellationToken);
public Task DeleteAsync(long objectId, CancellationToken cancellationToken = default)
=> _objectStorage.DeleteAsync(objectId, cancellationToken);
public Task DeleteAsync(long objectId, IRedbUser user, CancellationToken cancellationToken = default)
=> _objectStorage.DeleteAsync(objectId, user, cancellationToken);
public Task> AddNewObjectsAsync(IEnumerable> objects, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.AddNewObjectsAsync(objects, cancellationToken);
public Task> AddNewObjectsAsync(IEnumerable> objects, IRedbUser user, CancellationToken cancellationToken = default) where TProps : class, new()
=> _objectStorage.AddNewObjectsAsync(objects, user, cancellationToken);
public Task DeleteAsync(IEnumerable objectIds, CancellationToken cancellationToken = default)
=> _objectStorage.DeleteAsync(objectIds, cancellationToken);
public Task DeleteAsync(IEnumerable objectIds, IRedbUser user, CancellationToken cancellationToken = default)
=> _objectStorage.DeleteAsync(objectIds, user, cancellationToken);
public Task DeleteAsync(IEnumerable objects, CancellationToken cancellationToken = default)
=> _objectStorage.DeleteAsync(objects, cancellationToken);
public Task DeleteAsync(IEnumerable objects, IRedbUser user, CancellationToken cancellationToken = default)
=> _objectStorage.DeleteAsync(objects, user, cancellationToken);
public Task SoftDeleteAsync(IEnumerable objectIds, long? trashParentId = null, CancellationToken cancellationToken = default)
=> _objectStorage.SoftDeleteAsync(objectIds, trashParentId, cancellationToken);
public Task SoftDeleteAsync(IEnumerable objectIds, IRedbUser user, long? trashParentId = null, CancellationToken cancellationToken = default)
=> _objectStorage.SoftDeleteAsync(objectIds, user, trashParentId, cancellationToken);
public Task SoftDeleteAsync(IEnumerable objects, long? trashParentId = null, CancellationToken cancellationToken = default)
=> _objectStorage.SoftDeleteAsync(objects, trashParentId, cancellationToken);
public Task SoftDeleteAsync(IEnumerable objects, IRedbUser user, long? trashParentId = null, CancellationToken cancellationToken = default)
=> _objectStorage.SoftDeleteAsync(objects, user, trashParentId, cancellationToken);
public Task DeleteWithPurgeAsync(
IEnumerable objectIds,
int batchSize = 10,
IProgress? progress = null,
CancellationToken cancellationToken = default,
long? trashParentId = null)
=> _objectStorage.DeleteWithPurgeAsync(objectIds, batchSize, progress, cancellationToken, trashParentId);
public Task PurgeTrashAsync(
long trashId,
int totalCount,
int batchSize = 10,
IProgress? progress = null,
CancellationToken cancellationToken = default)
=> _objectStorage.PurgeTrashAsync(trashId, totalCount, batchSize, progress, cancellationToken);
public Task GetDeletionProgressAsync(long trashId, CancellationToken cancellationToken = default)
=> _objectStorage.GetDeletionProgressAsync(trashId, cancellationToken);
public Task> GetUserActiveDeletionsAsync(long userId, CancellationToken cancellationToken = default)
=> _objectStorage.GetUserActiveDeletionsAsync(userId, cancellationToken);
public Task> GetOrphanedDeletionTasksAsync(int timeoutMinutes = 30, CancellationToken cancellationToken = default)
=> _objectStorage.GetOrphanedDeletionTasksAsync(timeoutMinutes, cancellationToken);
public Task TryClaimOrphanedTaskAsync(long trashId, int timeoutMinutes = 30, CancellationToken cancellationToken = default)
=> _objectStorage.TryClaimOrphanedTaskAsync(trashId, timeoutMinutes, cancellationToken);
public Task LockForUpdateAsync(params long[] objectIds)
=> _objectStorage.LockForUpdateAsync(objectIds);
public Task LockForUpdateAsync(long[] objectIds, CancellationToken cancellationToken)
=> _objectStorage.LockForUpdateAsync(objectIds, cancellationToken);
public Task LockForUpdateRequiredAsync(params long[] objectIds)
=> _objectStorage.LockForUpdateRequiredAsync(objectIds);
public Task LockForUpdateRequiredAsync(long[] objectIds, CancellationToken cancellationToken)
=> _objectStorage.LockForUpdateRequiredAsync(objectIds, cancellationToken);
public Task> LoadAsync(IEnumerable objectIds, int depth = 10, CancellationToken cancellationToken = default)
=> _objectStorage.LoadAsync(objectIds, depth, cancellationToken);
public Task> LoadAsync(IEnumerable objectIds, IRedbUser user, int depth = 10, CancellationToken cancellationToken = default)
=> _objectStorage.LoadAsync(objectIds, user, depth, cancellationToken);
public Task> SaveAsync(IEnumerable objects, CancellationToken cancellationToken = default)
=> _objectStorage.SaveAsync(objects, cancellationToken);
public Task> SaveAsync(IEnumerable objects, IRedbUser user, CancellationToken cancellationToken = default)
=> _objectStorage.SaveAsync(objects, user, cancellationToken);
// V4 (LAZY Л2 §4.6): batch reload of reference stubs
public Task LoadReferencesAsync(RedbObject parent, Func?>?> references, CancellationToken cancellationToken = default)
where TProps : class, new() where TRef : class, new()
=> _objectStorage.LoadReferencesAsync(parent, references, cancellationToken);
public Task LoadReferencesAsync(RedbObject parent, Func?> reference, CancellationToken cancellationToken = default)
where TProps : class, new() where TRef : class, new()
=> _objectStorage.LoadReferencesAsync(parent, reference, cancellationToken);
// LoadWithParentsAsync - Load with parent chain to root
Task?> IObjectStorageProvider.LoadWithParentsAsync(long objectId, int depth, CancellationToken cancellationToken)
=> _objectStorage.LoadWithParentsAsync(objectId, depth, cancellationToken);
Task?> IObjectStorageProvider.LoadWithParentsAsync(IRedbObject obj, int depth, CancellationToken cancellationToken)
=> _objectStorage.LoadWithParentsAsync(obj, depth, cancellationToken);
Task?> IObjectStorageProvider.LoadWithParentsAsync(long objectId, IRedbUser user, int depth, CancellationToken cancellationToken)
=> _objectStorage.LoadWithParentsAsync(objectId, user, depth, cancellationToken);
Task?> IObjectStorageProvider.LoadWithParentsAsync(IRedbObject obj, IRedbUser user, int depth, CancellationToken cancellationToken)
=> _objectStorage.LoadWithParentsAsync(obj, user, depth, cancellationToken);
Task>> IObjectStorageProvider.LoadWithParentsAsync(IEnumerable objectIds, int depth, CancellationToken cancellationToken)
=> _objectStorage.LoadWithParentsAsync(objectIds, depth, cancellationToken);
Task>> IObjectStorageProvider.LoadWithParentsAsync(IEnumerable objectIds, IRedbUser user, int depth, CancellationToken cancellationToken)
=> _objectStorage.LoadWithParentsAsync(objectIds, user, depth, cancellationToken);
Task> IObjectStorageProvider.LoadWithParentsAsync(IEnumerable objectIds, int depth, CancellationToken cancellationToken)
=> _objectStorage.LoadWithParentsAsync(objectIds, depth, cancellationToken);
Task> IObjectStorageProvider.LoadWithParentsAsync(IEnumerable objectIds, IRedbUser user, int depth, CancellationToken cancellationToken)
=> _objectStorage.LoadWithParentsAsync(objectIds, user, depth, cancellationToken);
// === ITreeProvider DELEGATION ===
public Task DeleteSubtreeAsync(IRedbObject parentObj, CancellationToken cancellationToken = default)
=> _treeProvider.DeleteSubtreeAsync(parentObj, cancellationToken);
public Task DeleteSubtreeAsync(IRedbObject parentObj, IRedbUser user, CancellationToken cancellationToken = default)
=> _treeProvider.DeleteSubtreeAsync(parentObj, user, cancellationToken);
public Task DeleteSubtreeAsync(RedbObject parentObj, CancellationToken cancellationToken = default)
=> _treeProvider.DeleteSubtreeAsync(parentObj, cancellationToken);
public Task DeleteSubtreeAsync(RedbObject parentObj, IRedbUser user, CancellationToken cancellationToken = default)
=> _treeProvider.DeleteSubtreeAsync(parentObj, user, cancellationToken);
public Task> LoadTreeAsync(long rootObjectId, int? maxDepth = null, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.LoadTreeAsync(rootObjectId, maxDepth, cancellationToken);
public Task> LoadTreeAsync(IRedbObject rootObj, int? maxDepth = null, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.LoadTreeAsync(rootObj, maxDepth, cancellationToken);
public Task>> GetChildrenAsync(IRedbObject parentObj, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.GetChildrenAsync(parentObj, cancellationToken);
public Task>> GetPathToRootAsync(IRedbObject obj, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.GetPathToRootAsync(obj, cancellationToken);
public Task>> GetDescendantsAsync(IRedbObject parentObj, int? maxDepth = null, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.GetDescendantsAsync(parentObj, maxDepth, cancellationToken);
public Task MoveObjectAsync(IRedbObject obj, IRedbObject? newParentObj, CancellationToken cancellationToken = default)
=> _treeProvider.MoveObjectAsync(obj, newParentObj, cancellationToken);
public Task CreateChildAsync(TreeRedbObject obj, IRedbObject parentObj, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.CreateChildAsync(obj, parentObj, cancellationToken);
public Task> LoadTreeAsync(long rootObjectId, IRedbUser user, int? maxDepth = null, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.LoadTreeAsync(rootObjectId, user, maxDepth, cancellationToken);
public Task> LoadTreeAsync(IRedbObject rootObj, IRedbUser user, int? maxDepth = null, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.LoadTreeAsync(rootObj, user, maxDepth, cancellationToken);
public Task>> GetChildrenAsync(IRedbObject parentObj, IRedbUser user, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.GetChildrenAsync(parentObj, user, cancellationToken);
public Task>> GetPathToRootAsync(IRedbObject obj, IRedbUser user, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.GetPathToRootAsync(obj, user, cancellationToken);
public Task>> GetDescendantsAsync(IRedbObject parentObj, IRedbUser user, int? maxDepth = null, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.GetDescendantsAsync(parentObj, user, maxDepth, cancellationToken);
public Task MoveObjectAsync(IRedbObject obj, IRedbObject? newParentObj, IRedbUser user, CancellationToken cancellationToken = default)
=> _treeProvider.MoveObjectAsync(obj, newParentObj, user, cancellationToken);
public Task CreateChildAsync(TreeRedbObject obj, IRedbObject parentObj, IRedbUser user, CancellationToken cancellationToken = default) where TProps : class, new()
=> _treeProvider.CreateChildAsync(obj, parentObj, user, cancellationToken);
public Task LoadPolymorphicTreeAsync(IRedbObject rootObj, int? maxDepth = null, CancellationToken cancellationToken = default)
=> _treeProvider.LoadPolymorphicTreeAsync(rootObj, maxDepth, cancellationToken);
public Task> GetPolymorphicChildrenAsync(IRedbObject parentObj, CancellationToken cancellationToken = default)
=> _treeProvider.GetPolymorphicChildrenAsync(parentObj, cancellationToken);
public Task> GetPolymorphicPathToRootAsync(IRedbObject obj, CancellationToken cancellationToken = default)
=> _treeProvider.GetPolymorphicPathToRootAsync(obj, cancellationToken);
public Task> GetPolymorphicDescendantsAsync(IRedbObject parentObj, int? maxDepth = null, CancellationToken cancellationToken = default)
=> _treeProvider.GetPolymorphicDescendantsAsync(parentObj, maxDepth, cancellationToken);
public Task LoadPolymorphicTreeAsync(IRedbObject rootObj, IRedbUser user, int? maxDepth = null, CancellationToken cancellationToken = default)
=> _treeProvider.LoadPolymorphicTreeAsync(rootObj, user, maxDepth, cancellationToken);
public Task> GetPolymorphicChildrenAsync(IRedbObject parentObj, IRedbUser user, CancellationToken cancellationToken = default)
=> _treeProvider.GetPolymorphicChildrenAsync(parentObj, user, cancellationToken);
public Task> GetPolymorphicPathToRootAsync(IRedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _treeProvider.GetPolymorphicPathToRootAsync(obj, user, cancellationToken);
public Task> GetPolymorphicDescendantsAsync(IRedbObject parentObj, IRedbUser user, int? maxDepth = null, CancellationToken cancellationToken = default)
=> _treeProvider.GetPolymorphicDescendantsAsync(parentObj, user, maxDepth, cancellationToken);
public Task InitializeTypeRegistryAsync(CancellationToken cancellationToken = default)
=> _treeProvider.InitializeTypeRegistryAsync(cancellationToken);
// === IPermissionProvider DELEGATION ===
public IQueryable GetReadableObjectIds()
=> _permissionProvider.GetReadableObjectIds();
public Task CanUserEditObject(IRedbObject obj, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserEditObject(obj, cancellationToken);
public Task CanUserSelectObject(IRedbObject obj, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserSelectObject(obj, cancellationToken);
public Task CanUserInsertScheme(IRedbScheme scheme, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserInsertScheme(scheme, cancellationToken);
public Task CanUserInsertScheme(IRedbScheme scheme, IRedbUser user, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserInsertScheme(scheme, user, cancellationToken);
public Task CanUserDeleteObject(IRedbObject obj, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserDeleteObject(obj, cancellationToken);
public IQueryable GetReadableObjectIds(IRedbUser user)
=> _permissionProvider.GetReadableObjectIds(user);
public Task CanUserEditObject(IRedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserEditObject(obj, user, cancellationToken);
public Task CanUserSelectObject(IRedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserSelectObject(obj, user, cancellationToken);
public Task CanUserDeleteObject(IRedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserDeleteObject(obj, user, cancellationToken);
public Task CanUserEditObject(RedbObject obj, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserEditObject(obj, cancellationToken);
public Task CanUserSelectObject(RedbObject obj, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserSelectObject(obj, cancellationToken);
public Task CanUserDeleteObject(RedbObject obj, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserDeleteObject(obj, cancellationToken);
public Task CanUserEditObject(RedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserEditObject(obj, user, cancellationToken);
public Task CanUserSelectObject(RedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserSelectObject(obj, user, cancellationToken);
public Task CanUserDeleteObject(RedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserDeleteObject(obj, user, cancellationToken);
public Task CanUserInsertScheme(RedbObject obj, IRedbUser user, CancellationToken cancellationToken = default)
=> _permissionProvider.CanUserInsertScheme(obj, user, cancellationToken);
public Task CreatePermissionAsync(PermissionRequest request, IRedbUser? currentUser = null, CancellationToken cancellationToken = default)
=> _permissionProvider.CreatePermissionAsync(request, currentUser, cancellationToken);
public Task