Class CoreScope
Represents a core scope that manages transactional operations, caching, locking, and notifications.
Inheritance
Namespace: Umbraco.Cms.Core.Scoping
Assembly: Umbraco.Core.dll
Syntax
public class CoreScope : ICoreScope, IInstanceIdentifiable
Remarks
Scopes can be nested; a child scope must be completed before its parent.
The scope manages file system scoping, isolated caches, and notification publishing.
Constructors
View SourceCoreScope(IDistributedLockingMechanismFactory, ILoggerFactory, FileSystems, IEventAggregator, RepositoryCacheMode, bool?, IScopedNotificationPublisher?)
Initializes a new instance of the CoreScope class as a root scope.
Declaration
protected CoreScope(IDistributedLockingMechanismFactory distributedLockingMechanismFactory, ILoggerFactory loggerFactory, FileSystems scopedFileSystem, IEventAggregator eventAggregator, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, bool? shouldScopeFileSystems = null, IScopedNotificationPublisher? notificationPublisher = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IDistributedLockingMechanismFactory | distributedLockingMechanismFactory | The factory for creating distributed locking mechanisms. |
| ILoggerFactory | loggerFactory | The logger factory for creating loggers. |
| FileSystems | scopedFileSystem | The file systems to potentially scope. |
| IEventAggregator | eventAggregator | The event aggregator for publishing notifications. |
| RepositoryCacheMode | repositoryCacheMode | The repository cache mode for this scope. |
| bool? | shouldScopeFileSystems | A value indicating whether to scope the file systems. |
| IScopedNotificationPublisher | notificationPublisher | An optional scoped notification publisher. |
CoreScope(ICoreScope?, IDistributedLockingMechanismFactory, ILoggerFactory, FileSystems, IEventAggregator, RepositoryCacheMode, bool?, IScopedNotificationPublisher?)
Initializes a new instance of the CoreScope class with an optional parent scope.
Declaration
protected CoreScope(ICoreScope? parentScope, IDistributedLockingMechanismFactory distributedLockingMechanismFactory, ILoggerFactory loggerFactory, FileSystems scopedFileSystem, IEventAggregator eventAggregator, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, bool? shouldScopeFileSystems = null, IScopedNotificationPublisher? notificationPublisher = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScope | parentScope | The parent scope, or |
| IDistributedLockingMechanismFactory | distributedLockingMechanismFactory | The factory for creating distributed locking mechanisms. |
| ILoggerFactory | loggerFactory | The logger factory for creating loggers. |
| FileSystems | scopedFileSystem | The file systems to potentially scope. |
| IEventAggregator | eventAggregator | The event aggregator for publishing notifications. |
| RepositoryCacheMode | repositoryCacheMode | The repository cache mode for this scope. |
| bool? | shouldScopeFileSystems | A value indicating whether to scope the file systems. |
| IScopedNotificationPublisher | notificationPublisher | An optional scoped notification publisher. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when the repository cache mode is lower than the parent's mode, when a notification publisher is specified on a nested scope, or when the file system scoping differs from the parent. |
Fields
View SourceCompleted
Indicates whether the scope has been completed.
Declaration
protected bool? Completed
Field Value
| Type | Description |
|---|---|
| bool? |
Remarks
TODO (V18): Rename to _completed to comply with SA1306 (field names should begin with lowercase), or consider converting to a property.
Properties
View SourceCreatedThreadId
Gets the managed thread ID on which this instance was created.
Declaration
public int CreatedThreadId { get; }
Property Value
| Type | Description |
|---|---|
| int |
Depth
Gets the distance from the root scope.
Declaration
public int Depth { get; }
Property Value
| Type | Description |
|---|---|
| int |
Remarks
A zero represents a root scope, any value greater than zero represents a child scope.
HasParentScope
Gets a value indicating whether this scope has a parent scope.
Declaration
protected bool HasParentScope { get; }
Property Value
| Type | Description |
|---|---|
| bool |
InstanceId
Gets the instance unique identifier.
Declaration
public Guid InstanceId { get; }
Property Value
| Type | Description |
|---|---|
| Guid |
IsolatedCaches
Gets the scope isolated cache.
Declaration
public IsolatedCaches IsolatedCaches { get; }
Property Value
| Type | Description |
|---|---|
| IsolatedCaches |
Locks
Gets the locking mechanism for this scope.
Declaration
public ILockingMechanism Locks { get; }
Property Value
| Type | Description |
|---|---|
| ILockingMechanism |
Notifications
Gets the scope notification publisher
Declaration
public IScopedNotificationPublisher Notifications { get; }
Property Value
| Type | Description |
|---|---|
| IScopedNotificationPublisher |
RepositoryCacheMode
Gets the repositories cache mode.
Declaration
public RepositoryCacheMode RepositoryCacheMode { get; }
Property Value
| Type | Description |
|---|---|
| RepositoryCacheMode |
ScopedFileSystems
Gets a value indicating whether file systems are scoped for this scope.
Declaration
public bool ScopedFileSystems { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
View SourceChildCompleted(bool?)
Called when a child scope has completed, to update the parent's completion status.
Declaration
protected void ChildCompleted(bool? completed)
Parameters
| Type | Name | Description |
|---|---|---|
| bool? | completed | A value indicating whether the child completed successfully. |
Complete()
Completes a scope
Declaration
public bool Complete()
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether the scope is completed or not. |
Dispose()
Disposes the scope, handling file systems, notifications, and parent scope completion.
Declaration
public virtual void Dispose()
EagerReadLock(params int[])
Eagerly acquires read locks on the specified lock objects.
Declaration
public void EagerReadLock(params int[] lockIds)
Parameters
| Type | Name | Description |
|---|---|---|
| int[] | lockIds | Array of lock object identifiers. |
EagerReadLock(TimeSpan, int)
Eagerly acquires a read lock on a lock object with a timeout.
Declaration
public void EagerReadLock(TimeSpan timeout, int lockId)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The database timeout. |
| int | lockId | The lock object identifier. |
EagerWriteLock(params int[])
Eagerly acquires write locks on the specified lock objects.
Declaration
public void EagerWriteLock(params int[] lockIds)
Parameters
| Type | Name | Description |
|---|---|---|
| int[] | lockIds | Array of lock object identifiers. |
EagerWriteLock(TimeSpan, int)
Eagerly acquires a write lock on a lock object with a timeout.
Declaration
public void EagerWriteLock(TimeSpan timeout, int lockId)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The database timeout. |
| int | lockId | The lock object identifier. |
HandleScopedFileSystems()
Handles the completion and disposal of scoped file systems.
Declaration
protected void HandleScopedFileSystems()
HandleScopedNotifications()
Handles the scoped notifications when the scope exits.
Declaration
protected void HandleScopedNotifications()
ReadLock(params int[])
Read-locks some lock objects.
Declaration
public void ReadLock(params int[] lockIds)
Parameters
| Type | Name | Description |
|---|---|---|
| int[] | lockIds | Array of lock object identifiers. |
ReadLock(TimeSpan, int)
Read-locks some lock objects.
Declaration
public void ReadLock(TimeSpan timeout, int lockId)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The database timeout in milliseconds |
| int | lockId | The lock object identifier. |
SetParentScope(ICoreScope)
Sets the parent scope for this scope.
Declaration
protected void SetParentScope(ICoreScope coreScope)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScope | coreScope | The parent scope to set. |
WriteLock(params int[])
Write-locks some lock objects.
Declaration
public void WriteLock(params int[] lockIds)
Parameters
| Type | Name | Description |
|---|---|---|
| int[] | lockIds | Array of object identifiers. |
WriteLock(TimeSpan, int)
Write-locks some lock objects.
Declaration
public void WriteLock(TimeSpan timeout, int lockId)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | timeout | The database timeout in milliseconds |
| int | lockId | The lock object identifier. |