diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index 85c333e8b5..4a05cb0268 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -308,7 +308,7 @@ namespace Umbraco.Cms.Core.DependencyInjection Services.AddUnique(); Services.AddUnique(); Services.AddUnique(factory => new ExternalLoginService( - factory.GetRequiredService(), + factory.GetRequiredService(), factory.GetRequiredService(), factory.GetRequiredService(), factory.GetRequiredService() diff --git a/src/Umbraco.Core/DistributedLocking/IDistributedLockingMechanismFactory.cs b/src/Umbraco.Core/DistributedLocking/IDistributedLockingMechanismFactory.cs index f2eb80ade0..1bd1cfe206 100644 --- a/src/Umbraco.Core/DistributedLocking/IDistributedLockingMechanismFactory.cs +++ b/src/Umbraco.Core/DistributedLocking/IDistributedLockingMechanismFactory.cs @@ -5,5 +5,5 @@ namespace Umbraco.Cms.Core.DistributedLocking; /// public interface IDistributedLockingMechanismFactory { - IDistributedLockingMechanism? DistributedLockingMechanism { get; } + IDistributedLockingMechanism DistributedLockingMechanism { get; } } diff --git a/src/Umbraco.Core/Events/DeleteEventArgs.cs b/src/Umbraco.Core/Events/DeleteEventArgs.cs new file mode 100644 index 0000000000..0a3f76eeb8 --- /dev/null +++ b/src/Umbraco.Core/Events/DeleteEventArgs.cs @@ -0,0 +1,202 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Umbraco.Cms.Core.Events +{ + [SupersedeEvent(typeof(SaveEventArgs<>))] + [SupersedeEvent(typeof(PublishEventArgs<>))] + [SupersedeEvent(typeof(MoveEventArgs<>))] + [SupersedeEvent(typeof(CopyEventArgs<>))] + public class DeleteEventArgs : CancellableEnumerableObjectEventArgs, IEquatable>, IDeletingMediaFilesEventArgs + { + /// + /// Constructor accepting multiple entities that are used in the delete operation + /// + /// + /// + /// + public DeleteEventArgs(IEnumerable eventObject, bool canCancel, EventMessages eventMessages) : base(eventObject, canCancel, eventMessages) + { + MediaFilesToDelete = new List(); + } + + /// + /// Constructor accepting multiple entities that are used in the delete operation + /// + /// + /// + public DeleteEventArgs(IEnumerable eventObject, EventMessages eventMessages) : base(eventObject, eventMessages) + { + MediaFilesToDelete = new List(); + } + + /// + /// Constructor accepting a single entity instance + /// + /// + /// + public DeleteEventArgs(TEntity eventObject, EventMessages eventMessages) + : base(new List { eventObject }, eventMessages) + { + MediaFilesToDelete = new List(); + } + + /// + /// Constructor accepting a single entity instance + /// + /// + /// + /// + public DeleteEventArgs(TEntity eventObject, bool canCancel, EventMessages eventMessages) + : base(new List { eventObject }, canCancel, eventMessages) + { + MediaFilesToDelete = new List(); + } + + /// + /// Constructor accepting multiple entities that are used in the delete operation + /// + /// + /// + public DeleteEventArgs(IEnumerable eventObject, bool canCancel) : base(eventObject, canCancel) + { + MediaFilesToDelete = new List(); + } + + /// + /// Constructor accepting multiple entities that are used in the delete operation + /// + /// + public DeleteEventArgs(IEnumerable eventObject) : base(eventObject) + { + MediaFilesToDelete = new List(); + } + + /// + /// Constructor accepting a single entity instance + /// + /// + public DeleteEventArgs(TEntity eventObject) + : base(new List { eventObject }) + { + MediaFilesToDelete = new List(); + } + + /// + /// Constructor accepting a single entity instance + /// + /// + /// + public DeleteEventArgs(TEntity eventObject, bool canCancel) + : base(new List { eventObject }, canCancel) + { + MediaFilesToDelete = new List(); + } + + /// + /// Returns all entities that were deleted during the operation + /// + public IEnumerable DeletedEntities + { + get => EventObject; + set => EventObject = value; + } + + /// + /// A list of media files that can be added to during a deleted operation for which Umbraco will ensure are removed + /// + public List MediaFilesToDelete { get; private set; } + + public bool Equals(DeleteEventArgs other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return base.Equals(other) && MediaFilesToDelete.SequenceEqual(other.MediaFilesToDelete); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((DeleteEventArgs) obj); + } + + public override int GetHashCode() + { + unchecked + { + return (base.GetHashCode() * 397) ^ MediaFilesToDelete.GetHashCode(); + } + } + + public static bool operator ==(DeleteEventArgs left, DeleteEventArgs right) + { + return Equals(left, right); + } + + public static bool operator !=(DeleteEventArgs left, DeleteEventArgs right) + { + return !Equals(left, right); + } + } + + public class DeleteEventArgs : CancellableEventArgs, IEquatable + { + public DeleteEventArgs(int id, bool canCancel, EventMessages eventMessages) + : base(canCancel, eventMessages) + { + Id = id; + } + + public DeleteEventArgs(int id, bool canCancel) + : base(canCancel) + { + Id = id; + } + + public DeleteEventArgs(int id) + { + Id = id; + } + + /// + /// Gets the Id of the object being deleted. + /// + public int Id { get; private set; } + + public bool Equals(DeleteEventArgs other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return base.Equals(other) && Id == other.Id; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((DeleteEventArgs) obj); + } + + public override int GetHashCode() + { + unchecked + { + return (base.GetHashCode() * 397) ^ Id; + } + } + + public static bool operator ==(DeleteEventArgs left, DeleteEventArgs right) + { + return Equals(left, right); + } + + public static bool operator !=(DeleteEventArgs left, DeleteEventArgs right) + { + return !Equals(left, right); + } + } +} diff --git a/src/Umbraco.Core/Events/IDeletingMediaFilesEventArgs.cs b/src/Umbraco.Core/Events/IDeletingMediaFilesEventArgs.cs new file mode 100644 index 0000000000..9a6a4357e0 --- /dev/null +++ b/src/Umbraco.Core/Events/IDeletingMediaFilesEventArgs.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Umbraco.Cms.Core.Events +{ + public interface IDeletingMediaFilesEventArgs + { + List MediaFilesToDelete { get; } + } +} diff --git a/src/Umbraco.Core/Events/IEventDispatcher.cs b/src/Umbraco.Core/Events/IEventDispatcher.cs new file mode 100644 index 0000000000..84e522761c --- /dev/null +++ b/src/Umbraco.Core/Events/IEventDispatcher.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; + +namespace Umbraco.Cms.Core.Events +{ + /// + /// Dispatches events from within a scope. + /// + /// + /// The name of the event is auto-magically discovered by matching the sender type, args type, and + /// eventHandler type. If the match is not unique, then the name parameter must be used to specify the + /// name in an explicit way. + /// What happens when an event is dispatched depends on the scope settings. It can be anything from + /// "trigger immediately" to "just ignore". Refer to the scope documentation for more details. + /// + public interface IEventDispatcher + { + // not sure about the Dispatch & DispatchCancelable signatures at all for now + // nor about the event name thing, etc - but let's keep it like this + + /// + /// Dispatches a cancelable event. + /// + /// The event handler. + /// The object that raised the event. + /// The event data. + /// The optional name of the event. + /// A value indicating whether the cancelable event was cancelled. + /// See general remarks on the interface. + bool DispatchCancelable(EventHandler eventHandler, object sender, CancellableEventArgs args, string name = null); + + /// + /// Dispatches a cancelable event. + /// + /// The event handler. + /// The object that raised the event. + /// The event data. + /// The optional name of the event. + /// A value indicating whether the cancelable event was cancelled. + /// See general remarks on the interface. + bool DispatchCancelable(EventHandler eventHandler, object sender, TArgs args, string name = null) + where TArgs : CancellableEventArgs; + + /// + /// Dispatches a cancelable event. + /// + /// The event handler. + /// The object that raised the event. + /// The event data. + /// The optional name of the event. + /// A value indicating whether the cancelable event was cancelled. + /// See general remarks on the interface. + bool DispatchCancelable(TypedEventHandler eventHandler, TSender sender, TArgs args, string name = null) + where TArgs : CancellableEventArgs; + + /// + /// Dispatches an event. + /// + /// The event handler. + /// The object that raised the event. + /// The event data. + /// The optional name of the event. + /// See general remarks on the interface. + void Dispatch(EventHandler eventHandler, object sender, EventArgs args, string name = null); + + /// + /// Dispatches an event. + /// + /// The event handler. + /// The object that raised the event. + /// The event data. + /// The optional name of the event. + /// See general remarks on the interface. + void Dispatch(EventHandler eventHandler, object sender, TArgs args, string name = null); + + /// + /// Dispatches an event. + /// + /// The event handler. + /// The object that raised the event. + /// The event data. + /// The optional name of the event. + /// See general remarks on the interface. + void Dispatch(TypedEventHandler eventHandler, TSender sender, TArgs args, string name = null); + + /// + /// Notifies the dispatcher that the scope is exiting. + /// + /// A value indicating whether the scope completed. + void ScopeExit(bool completed); + + /// + /// Gets the collected events. + /// + /// The collected events. + IEnumerable GetEvents(EventDefinitionFilter filter); + } +} diff --git a/src/Umbraco.Core/Events/PassThroughEventDispatcher.cs b/src/Umbraco.Core/Events/PassThroughEventDispatcher.cs new file mode 100644 index 0000000000..0b2e72cc7f --- /dev/null +++ b/src/Umbraco.Core/Events/PassThroughEventDispatcher.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Umbraco.Cms.Core.Events +{ + /// + /// An IEventDispatcher that immediately raise all events. + /// + /// This means that events will be raised during the scope transaction, + /// whatever happens, and the transaction could roll back in the end. + internal class PassThroughEventDispatcher : IEventDispatcher + { + public bool DispatchCancelable(EventHandler eventHandler, object sender, CancellableEventArgs args, string eventName = null) + { + if (eventHandler == null) return args.Cancel; + eventHandler(sender, args); + return args.Cancel; + } + + public bool DispatchCancelable(EventHandler eventHandler, object sender, TArgs args, string eventName = null) + where TArgs : CancellableEventArgs + { + if (eventHandler == null) return args.Cancel; + eventHandler(sender, args); + return args.Cancel; + } + + public bool DispatchCancelable(TypedEventHandler eventHandler, TSender sender, TArgs args, string eventName = null) + where TArgs : CancellableEventArgs + { + if (eventHandler == null) return args.Cancel; + eventHandler(sender, args); + return args.Cancel; + } + + public void Dispatch(EventHandler eventHandler, object sender, EventArgs args, string eventName = null) + { + eventHandler?.Invoke(sender, args); + } + + public void Dispatch(EventHandler eventHandler, object sender, TArgs args, string eventName = null) + { + eventHandler?.Invoke(sender, args); + } + + public void Dispatch(TypedEventHandler eventHandler, TSender sender, TArgs args, string eventName = null) + { + eventHandler?.Invoke(sender, args); + } + + public IEnumerable GetEvents(EventDefinitionFilter filter) + { + return Enumerable.Empty(); + } + + public void ScopeExit(bool completed) + { } + } +} diff --git a/src/Umbraco.Core/Events/QueuingEventDispatcher.cs b/src/Umbraco.Core/Events/QueuingEventDispatcher.cs new file mode 100644 index 0000000000..e79cd67cd8 --- /dev/null +++ b/src/Umbraco.Core/Events/QueuingEventDispatcher.cs @@ -0,0 +1,43 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Umbraco.Cms.Core.IO; + +namespace Umbraco.Cms.Core.Events +{ + /// + /// An IEventDispatcher that queues events, and raise them when the scope + /// exits and has been completed. + /// + public class QueuingEventDispatcher : QueuingEventDispatcherBase + { + private readonly MediaFileManager _mediaFileManager; + public QueuingEventDispatcher(MediaFileManager mediaFileManager) + : base(true) + { + _mediaFileManager = mediaFileManager; + } + + protected override void ScopeExitCompleted() + { + // processing only the last instance of each event... + // this is probably far from perfect, because if eg a content is saved in a list + // and then as a single content, the two events will probably not be de-duplicated, + // but it's better than nothing + + foreach (var e in GetEvents(EventDefinitionFilter.LastIn)) + { + e.RaiseEvent(); + + // separating concerns means that this should probably not be here, + // but then where should it be (without making things too complicated)? + var delete = e.Args as IDeletingMediaFilesEventArgs; + if (delete != null && delete.MediaFilesToDelete.Count > 0) + _mediaFileManager.DeleteMediaFiles(delete.MediaFilesToDelete); + } + } + + + + } +} diff --git a/src/Umbraco.Core/Events/QueuingEventDispatcherBase.cs b/src/Umbraco.Core/Events/QueuingEventDispatcherBase.cs new file mode 100644 index 0000000000..784390ebe7 --- /dev/null +++ b/src/Umbraco.Core/Events/QueuingEventDispatcherBase.cs @@ -0,0 +1,344 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Cms.Core.Collections; +using Umbraco.Cms.Core.Composing; +using Umbraco.Cms.Core.Models.Entities; +using Umbraco.Extensions; + +namespace Umbraco.Cms.Core.Events +{ + /// + /// An IEventDispatcher that queues events. + /// + /// + /// Can raise, or ignore, cancelable events, depending on option. + /// Implementations must override ScopeExitCompleted to define what + /// to do with the events when the scope exits and has been completed. + /// If the scope exits without being completed, events are ignored. + /// + public abstract class QueuingEventDispatcherBase : IEventDispatcher + { + //events will be enlisted in the order they are raised + private List _events; + private readonly bool _raiseCancelable; + + protected QueuingEventDispatcherBase(bool raiseCancelable) + { + _raiseCancelable = raiseCancelable; + } + + private List Events => _events ?? (_events = new List()); + + public bool DispatchCancelable(EventHandler eventHandler, object sender, CancellableEventArgs args, string eventName = null) + { + if (eventHandler == null) return args.Cancel; + if (_raiseCancelable == false) return args.Cancel; + eventHandler(sender, args); + return args.Cancel; + } + + public bool DispatchCancelable(EventHandler eventHandler, object sender, TArgs args, string eventName = null) + where TArgs : CancellableEventArgs + { + if (eventHandler == null) return args.Cancel; + if (_raiseCancelable == false) return args.Cancel; + eventHandler(sender, args); + return args.Cancel; + } + + public bool DispatchCancelable(TypedEventHandler eventHandler, TSender sender, TArgs args, string eventName = null) + where TArgs : CancellableEventArgs + { + if (eventHandler == null) return args.Cancel; + if (_raiseCancelable == false) return args.Cancel; + eventHandler(sender, args); + return args.Cancel; + } + + public void Dispatch(EventHandler eventHandler, object sender, EventArgs args, string eventName = null) + { + if (eventHandler == null) return; + Events.Add(new EventDefinition(eventHandler, sender, args, eventName)); + } + + public void Dispatch(EventHandler eventHandler, object sender, TArgs args, string eventName = null) + { + if (eventHandler == null) return; + Events.Add(new EventDefinition(eventHandler, sender, args, eventName)); + } + + public void Dispatch(TypedEventHandler eventHandler, TSender sender, TArgs args, string eventName = null) + { + if (eventHandler == null) return; + Events.Add(new EventDefinition(eventHandler, sender, args, eventName)); + } + + public IEnumerable GetEvents(EventDefinitionFilter filter) + { + if (_events == null) + return Enumerable.Empty(); + + IReadOnlyList events; + switch (filter) + { + case EventDefinitionFilter.All: + events = _events; + break; + case EventDefinitionFilter.FirstIn: + var l1 = new OrderedHashSet(); + foreach (var e in _events) + l1.Add(e); + events = l1; + break; + case EventDefinitionFilter.LastIn: + var l2 = new OrderedHashSet(keepOldest: false); + foreach (var e in _events) + l2.Add(e); + events = l2; + break; + default: + throw new ArgumentOutOfRangeException("filter", filter, null); + } + + return FilterSupersededAndUpdateToLatestEntity(events); + } + + private class EventDefinitionInfos + { + public IEventDefinition EventDefinition { get; set; } + public Type[] SupersedeTypes { get; set; } + } + + // this is way too convoluted, the supersede attribute is used only on DeleteEventargs to specify + // that it supersedes save, publish, move and copy - BUT - publish event args is also used for + // unpublishing and should NOT be superseded - so really it should not be managed at event args + // level but at event level + // + // what we want is: + // if an entity is deleted, then all Saved, Moved, Copied, Published events prior to this should + // not trigger for the entity - and even though, does it make any sense? making a copy of an entity + // should ... trigger? + // + // not going to refactor it all - we probably want to *always* trigger event but tell people that + // due to scopes, they should not expected eg a saved entity to still be around - however, now, + // going to write a ugly condition to deal with U4-10764 + + // iterates over the events (latest first) and filter out any events or entities in event args that are included + // in more recent events that Supersede previous ones. For example, If an Entity has been Saved and then Deleted, we don't want + // to raise the Saved event (well actually we just don't want to include it in the args for that saved event) + internal static IEnumerable FilterSupersededAndUpdateToLatestEntity(IReadOnlyList events) + { + // keeps the 'latest' entity and associated event data + var entities = new List>(); + + // collects the event definitions + // collects the arguments in result, that require their entities to be updated + var result = new List(); + var resultArgs = new List(); + + // eagerly fetch superseded arg types for each arg type + var argTypeSuperceeding = events.Select(x => x.Args.GetType()) + .Distinct() + .ToDictionary(x => x, x => x.GetCustomAttributes(false).Select(y => y.SupersededEventArgsType).ToArray()); + + // iterate over all events and filter + // + // process the list in reverse, because events are added in the order they are raised and we want to keep + // the latest (most recent) entities and filter out what is not relevant anymore (too old), eg if an entity + // is Deleted after being Saved, we want to filter out the Saved event + for (var index = events.Count - 1; index >= 0; index--) + { + var def = events[index]; + + var infos = new EventDefinitionInfos + { + EventDefinition = def, + SupersedeTypes = argTypeSuperceeding[def.Args.GetType()] + }; + + var args = def.Args as CancellableObjectEventArgs; + if (args == null) + { + // not a cancellable event arg, include event definition in result + result.Add(def); + } + else + { + // event object can either be a single object or an enumerable of objects + // try to get as an enumerable, get null if it's not + var eventObjects = TypeHelper.CreateGenericEnumerableFromObject(args.EventObject); + if (eventObjects == null) + { + // single object, cast as an IEntity + // if cannot cast, cannot filter, nothing - just include event definition in result + var eventEntity = args.EventObject as IEntity; + if (eventEntity == null) + { + result.Add(def); + continue; + } + + // look for this entity in superseding event args + // found = must be removed (ie not added), else track + if (IsSuperceeded(eventEntity, infos, entities) == false) + { + // track + entities.Add(Tuple.Create(eventEntity, infos)); + + // track result arguments + // include event definition in result + resultArgs.Add(args); + result.Add(def); + } + } + else + { + // enumerable of objects + var toRemove = new List(); + foreach (var eventObject in eventObjects) + { + // extract the event object, cast as an IEntity + // if cannot cast, cannot filter, nothing to do - just leave it in the list & continue + var eventEntity = eventObject as IEntity; + if (eventEntity == null) + continue; + + // look for this entity in superseding event args + // found = must be removed, else track + if (IsSuperceeded(eventEntity, infos, entities)) + toRemove.Add(eventEntity); + else + entities.Add(Tuple.Create(eventEntity, infos)); + } + + // remove superseded entities + foreach (var entity in toRemove) + eventObjects.Remove(entity); + + // if there are still entities in the list, keep the event definition + if (eventObjects.Count > 0) + { + if (toRemove.Count > 0) + { + // re-assign if changed + args.EventObject = eventObjects; + } + + // track result arguments + // include event definition in result + resultArgs.Add(args); + result.Add(def); + } + } + } + } + + // go over all args in result, and update them with the latest instanceof each entity + UpdateToLatestEntities(entities, resultArgs); + + // reverse, since we processed the list in reverse + result.Reverse(); + + return result; + } + + // edits event args to use the latest instance of each entity + private static void UpdateToLatestEntities(IEnumerable> entities, IEnumerable args) + { + // get the latest entities + // ordered hash set + keepOldest will keep the latest inserted entity (in case of duplicates) + var latestEntities = new OrderedHashSet(keepOldest: true); + foreach (var entity in entities.OrderByDescending(entity => entity.Item1.UpdateDate)) + latestEntities.Add(entity.Item1); + + foreach (var arg in args) + { + // event object can either be a single object or an enumerable of objects + // try to get as an enumerable, get null if it's not + var eventObjects = TypeHelper.CreateGenericEnumerableFromObject(arg.EventObject); + if (eventObjects == null) + { + // single object + // look for a more recent entity for that object, and replace if any + // works by "equalling" entities ie the more recent one "equals" this one (though different object) + var foundEntity = latestEntities.FirstOrDefault(x => Equals(x, arg.EventObject)); + if (foundEntity != null) + arg.EventObject = foundEntity; + } + else + { + // enumerable of objects + // same as above but for each object + var updated = false; + for (var i = 0; i < eventObjects.Count; i++) + { + var foundEntity = latestEntities.FirstOrDefault(x => Equals(x, eventObjects[i])); + if (foundEntity == null) continue; + eventObjects[i] = foundEntity; + updated = true; + } + + if (updated) + arg.EventObject = eventObjects; + } + } + } + + // determines if a given entity, appearing in a given event definition, should be filtered out, + // considering the entities that have already been visited - an entity is filtered out if it + // appears in another even definition, which supersedes this event definition. + private static bool IsSuperceeded(IEntity entity, EventDefinitionInfos infos, List> entities) + { + //var argType = meta.EventArgsType; + var argType = infos.EventDefinition.Args.GetType(); + + // look for other instances of the same entity, coming from an event args that supersedes other event args, + // ie is marked with the attribute, and is not this event args (cannot supersede itself) + var superceeding = entities + .Where(x => x.Item2.SupersedeTypes.Length > 0 // has the attribute + && x.Item2.EventDefinition.Args.GetType() != argType // is not the same + && Equals(x.Item1, entity)) // same entity + .ToArray(); + + // first time we see this entity = not filtered + if (superceeding.Length == 0) + return false; + + // delete event args does NOT supersedes 'unpublished' event + if (argType.IsGenericType && argType.GetGenericTypeDefinition() == typeof(PublishEventArgs<>) && infos.EventDefinition.EventName == "Unpublished") + return false; + + // found occurrences, need to determine if this event args is superseded + if (argType.IsGenericType) + { + // generic, must compare type arguments + var supercededBy = superceeding.FirstOrDefault(x => + x.Item2.SupersedeTypes.Any(y => + // superseding a generic type which has the same generic type definition + // (but ... no matter the generic type parameters? could be different?) + y.IsGenericTypeDefinition && y == argType.GetGenericTypeDefinition() + // or superceeding a non-generic type which is ... (but... how is this ever possible? argType *is* generic? + || y.IsGenericTypeDefinition == false && y == argType)); + return supercededBy != null; + } + else + { + // non-generic, can compare types 1:1 + var supercededBy = superceeding.FirstOrDefault(x => + x.Item2.SupersedeTypes.Any(y => y == argType)); + return supercededBy != null; + } + } + + public void ScopeExit(bool completed) + { + if (_events == null) return; + if (completed) + ScopeExitCompleted(); + _events.Clear(); + } + + protected abstract void ScopeExitCompleted(); + } +} diff --git a/src/Umbraco.Core/Scoping/ICoreScope.cs b/src/Umbraco.Core/Scoping/ICoreScope.cs new file mode 100644 index 0000000000..8bb85ca29d --- /dev/null +++ b/src/Umbraco.Core/Scoping/ICoreScope.cs @@ -0,0 +1,67 @@ +using System; +using Umbraco.Cms.Core.Cache; +using Umbraco.Cms.Core.Events; + +namespace Umbraco.Cms.Core.Scoping; + +/// +/// Represents a scope. +/// +public interface ICoreScope : IDisposable, IInstanceIdentifiable +{ + /// + /// Gets the scope notification publisher + /// + IScopedNotificationPublisher Notifications { get; } + + /// + /// Gets the repositories cache mode. + /// + RepositoryCacheMode RepositoryCacheMode { get; } + + /// + /// Gets the scope isolated cache. + /// + IsolatedCaches IsolatedCaches { get; } + + /// + /// Completes the scope. + /// + /// A value indicating whether the scope has been successfully completed. + /// Can return false if any child scope has not completed. + bool Complete(); + + /// + /// Read-locks some lock objects. + /// + /// Array of lock object identifiers. + void ReadLock(params int[] lockIds); + + /// + /// Write-locks some lock objects. + /// + /// Array of object identifiers. + void WriteLock(params int[] lockIds); + + /// + /// Write-locks some lock objects. + /// + /// The database timeout in milliseconds + /// The lock object identifier. + void WriteLock(TimeSpan timeout, int lockId); + + /// + /// Read-locks some lock objects. + /// + /// The database timeout in milliseconds + /// The lock object identifier. + void ReadLock(TimeSpan timeout, int lockId); + + void EagerWriteLock(params int[] lockIds); + + void EagerWriteLock(TimeSpan timeout, int lockId); + + void EagerReadLock(TimeSpan timeout, int lockId); + + void EagerReadLock(params int[] lockIds); +} diff --git a/src/Umbraco.Core/Scoping/IScopeProvider.cs b/src/Umbraco.Core/Scoping/ICoreScopeProvider.cs similarity index 51% rename from src/Umbraco.Core/Scoping/IScopeProvider.cs rename to src/Umbraco.Core/Scoping/ICoreScopeProvider.cs index c9c30662b4..d4fe496d38 100644 --- a/src/Umbraco.Core/Scoping/IScopeProvider.cs +++ b/src/Umbraco.Core/Scoping/ICoreScopeProvider.cs @@ -2,22 +2,19 @@ using System.Data; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Persistence.Querying; -#if DEBUG_SCOPES -using System.Collections.Generic; -#endif - namespace Umbraco.Cms.Core.Scoping { /// /// Provides scopes. /// - public interface IScopeProvider + public interface ICoreScopeProvider { /// /// Creates an ambient scope. /// /// The transaction isolation level. /// The repositories cache mode. + /// An optional events dispatcher. /// An optional notification publisher. /// A value indicating whether to scope the filesystems. /// A value indicating whether this scope should always be registered in the call context. @@ -31,52 +28,15 @@ namespace Umbraco.Cms.Core.Scoping /// Auto-completed scopes should be used for read-only operations ONLY. Do not use them if you do not /// understand the associated issues, such as the scope being completed even though an exception is thrown. /// - IScope CreateScope( + ICoreScope CreateCoreScope( IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + IEventDispatcher? eventDispatcher = null, IScopedNotificationPublisher? scopedNotificationPublisher = null, bool? scopeFileSystems = null, bool callContext = false, bool autoComplete = false); - /// - /// Creates a detached scope. - /// - /// A detached scope. - /// The transaction isolation level. - /// The repositories cache mode. - /// An option notification publisher. - /// A value indicating whether to scope the filesystems. - /// - /// A detached scope is not ambient and has no parent. - /// It is meant to be attached by . - /// - // TODO: This is not actually used apart from unit tests - I'm assuming it's maybe used by Deploy? - IScope CreateDetachedScope( - IsolationLevel isolationLevel = IsolationLevel.Unspecified, - RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, - IScopedNotificationPublisher? scopedNotificationPublisher = null, - bool? scopeFileSystems = null); - - /// - /// Attaches a scope. - /// - /// The scope to attach. - /// A value indicating whether to force usage of call context. - /// - /// Only a scope created by can be attached. - /// - void AttachScope(IScope scope, bool callContext = false); - - /// - /// Detaches a scope. - /// - /// The detached scope. - /// - /// Only a scope previously attached by can be detached. - /// - IScope DetachScope(); - /// /// Gets the scope context. /// @@ -86,11 +46,5 @@ namespace Umbraco.Cms.Core.Scoping /// Creates an instance of /// IQuery CreateQuery(); - -#if DEBUG_SCOPES - - IEnumerable ScopeInfos { get; } - ScopeInfo GetScopeInfo(IScope scope); -#endif } } diff --git a/src/Umbraco.Core/Scoping/IScope.cs b/src/Umbraco.Core/Scoping/IScope.cs deleted file mode 100644 index 312be1a35f..0000000000 --- a/src/Umbraco.Core/Scoping/IScope.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using Umbraco.Cms.Core.Cache; -using Umbraco.Cms.Core.Events; - -namespace Umbraco.Cms.Core.Scoping -{ - /// - /// Represents a scope. - /// - public interface IScope : IDisposable, IInstanceIdentifiable - { - /// - /// Gets the scope notification publisher - /// - IScopedNotificationPublisher Notifications { get; } - - /// - /// Gets the repositories cache mode. - /// - RepositoryCacheMode RepositoryCacheMode { get; } - - /// - /// Gets the scope isolated cache. - /// - IsolatedCaches IsolatedCaches { get; } - - /// - /// Completes the scope. - /// - /// A value indicating whether the scope has been successfully completed. - /// Can return false if any child scope has not completed. - bool Complete(); - - /// - /// Read-locks some lock objects. - /// - /// Array of lock object identifiers. - void ReadLock(params int[] lockIds); - - /// - /// Write-locks some lock objects. - /// - /// Array of object identifiers. - void WriteLock(params int[] lockIds); - - /// - /// Write-locks some lock objects. - /// - /// The database timeout in milliseconds - /// The lock object identifier. - void WriteLock(TimeSpan timeout, int lockId); - - /// - /// Read-locks some lock objects. - /// - /// The database timeout in milliseconds - /// The lock object identifier. - void ReadLock(TimeSpan timeout, int lockId); - - void EagerWriteLock(params int[] lockIds); - - void EagerWriteLock(TimeSpan timeout, int lockId); - - void EagerReadLock(TimeSpan timeout, int lockId); - - void EagerReadLock(params int[] lockIds); - } -} diff --git a/src/Umbraco.Core/Scoping/IScopeContext.cs b/src/Umbraco.Core/Scoping/IScopeContext.cs index 72523be9e2..7f1302911a 100644 --- a/src/Umbraco.Core/Scoping/IScopeContext.cs +++ b/src/Umbraco.Core/Scoping/IScopeContext.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Umbraco.Cms.Core.Scoping { diff --git a/src/Umbraco.Core/Services/ConsentService.cs b/src/Umbraco.Core/Services/ConsentService.cs index bb4d989676..9a767d9c4e 100644 --- a/src/Umbraco.Core/Services/ConsentService.cs +++ b/src/Umbraco.Core/Services/ConsentService.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Services /// /// Initializes a new instance of the class. /// - public ConsentService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IConsentRepository consentRepository) + public ConsentService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IConsentRepository consentRepository) : base(provider, loggerFactory, eventMessagesFactory) { _consentRepository = consentRepository; @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Services Comment = comment }; - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _consentRepository.ClearCurrent(source, context, action); _consentRepository.Save(consent); @@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Services bool sourceStartsWith = false, bool contextStartsWith = false, bool actionStartsWith = false, bool includeHistory = false) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query(); diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 35a6efe450..1b790c9867 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Core.Services #region Constructors - public ContentService(IScopeProvider provider, ILoggerFactory loggerFactory, + public ContentService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IDocumentRepository documentRepository, IEntityRepository entityRepository, IAuditRepository auditRepository, @@ -89,7 +89,7 @@ namespace Umbraco.Cms.Core.Services // Store the result of doing the save of content for the rollback OperationResult rollbackSaveResult; - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var rollingBackNotification = new ContentRollingBackNotification(content, evtMsgs); if (scope.Notifications.PublishCancelable(rollingBackNotification)) @@ -136,7 +136,7 @@ namespace Umbraco.Cms.Core.Services public int CountPublished(string? contentTypeAlias = null) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.CountPublished(contentTypeAlias); @@ -145,7 +145,7 @@ namespace Umbraco.Cms.Core.Services public int Count(string? contentTypeAlias = null) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.Count(contentTypeAlias); @@ -154,7 +154,7 @@ namespace Umbraco.Cms.Core.Services public int CountChildren(int parentId, string? contentTypeAlias = null) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.CountChildren(parentId, contentTypeAlias); @@ -163,7 +163,7 @@ namespace Umbraco.Cms.Core.Services public int CountDescendants(int parentId, string? contentTypeAlias = null) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.CountDescendants(parentId, contentTypeAlias); @@ -181,7 +181,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetPermissions(EntityPermissionSet permissionSet) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); _documentRepository.ReplaceContentPermissions(permissionSet); @@ -197,7 +197,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetPermission(IContent entity, char permission, IEnumerable groupIds) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); _documentRepository.AssignEntityPermission(entity, permission, groupIds); @@ -212,7 +212,7 @@ namespace Umbraco.Cms.Core.Services /// public EntityPermissionCollection GetPermissions(IContent content) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetPermissionsForEntity(content.Id); @@ -351,7 +351,7 @@ namespace Umbraco.Cms.Core.Services { // TODO: what about culture? - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // locking the content tree secures content types too scope.WriteLock(Constants.Locks.ContentTree); @@ -398,7 +398,7 @@ namespace Umbraco.Cms.Core.Services throw new ArgumentNullException(nameof(parent)); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // locking the content tree secures content types too scope.WriteLock(Constants.Locks.ContentTree); @@ -431,7 +431,7 @@ namespace Umbraco.Cms.Core.Services /// public IContent? GetById(int id) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.Get(id); @@ -453,7 +453,7 @@ namespace Umbraco.Cms.Core.Services return Enumerable.Empty(); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); IEnumerable items = _documentRepository.GetMany(idsA); @@ -471,7 +471,7 @@ namespace Umbraco.Cms.Core.Services /// public IContent? GetById(Guid key) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.Get(key); @@ -481,7 +481,7 @@ namespace Umbraco.Cms.Core.Services /// public ContentScheduleCollection GetContentScheduleByContentId(int contentId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.ContentTree); return _documentRepository.GetContentSchedule(contentId); @@ -491,7 +491,7 @@ namespace Umbraco.Cms.Core.Services /// public void PersistContentSchedule(IContent content, ContentScheduleCollection contentSchedule) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.WriteLock(Cms.Core.Constants.Locks.ContentTree); _documentRepository.PersistContentSchedule(content, contentSchedule); @@ -521,7 +521,7 @@ namespace Umbraco.Cms.Core.Services return Enumerable.Empty(); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); IEnumerable? items = _documentRepository.GetMany(idsA); @@ -557,7 +557,7 @@ namespace Umbraco.Cms.Core.Services ordering = Ordering.By("sortOrder"); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetPage( @@ -585,7 +585,7 @@ namespace Umbraco.Cms.Core.Services ordering = Ordering.By("sortOrder"); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetPage( @@ -602,7 +602,7 @@ namespace Umbraco.Cms.Core.Services /// Contrary to most methods, this method filters out trashed content items. public IEnumerable? GetByLevel(int level) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); IQuery? query = Query().Where(x => x.Level == level && x.Trashed == false); @@ -617,7 +617,7 @@ namespace Umbraco.Cms.Core.Services /// An item public IContent? GetVersion(int versionId) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetVersion(versionId); @@ -631,7 +631,7 @@ namespace Umbraco.Cms.Core.Services /// An Enumerable list of objects public IEnumerable GetVersions(int id) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetAllVersions(id); @@ -644,7 +644,7 @@ namespace Umbraco.Cms.Core.Services /// An Enumerable list of objects public IEnumerable GetVersionsSlim(int id, int skip, int take) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetAllVersionsSlim(id, skip, take); @@ -659,7 +659,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetVersionIds(int id, int maxRows) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _documentRepository.GetVersionIds(id, maxRows); } @@ -696,7 +696,7 @@ namespace Umbraco.Cms.Core.Services return new List(); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetMany(ids!); @@ -710,7 +710,7 @@ namespace Umbraco.Cms.Core.Services /// An Enumerable list of published objects public IEnumerable? GetPublishedChildren(int id) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); IQuery? query = Query().Where(x => x.ParentId == id && x.Published); @@ -737,7 +737,7 @@ namespace Umbraco.Cms.Core.Services ordering = Ordering.By("sortOrder"); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); @@ -755,7 +755,7 @@ namespace Umbraco.Cms.Core.Services ordering = Ordering.By("Path"); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); @@ -845,7 +845,7 @@ namespace Umbraco.Cms.Core.Services /// An Enumerable list of objects public IEnumerable GetRootContent() { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); IQuery query = Query().Where(x => x.ParentId == Constants.System.Root); @@ -859,7 +859,7 @@ namespace Umbraco.Cms.Core.Services /// internal IEnumerable? GetAllPublished() { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.Get(QueryNotTrashed); @@ -869,7 +869,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetContentForExpiration(DateTime date) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetContentForExpiration(date); @@ -879,7 +879,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetContentForRelease(DateTime date) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.GetContentForRelease(date); @@ -893,7 +893,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetPagedContentInRecycleBin(long pageIndex, int pageSize, out long totalRecords, IQuery? filter = null, Ordering? ordering = null) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { if (ordering == null) { @@ -939,7 +939,7 @@ namespace Umbraco.Cms.Core.Services public bool IsPathPublished(IContent? content) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.IsPathPublished(content); @@ -969,7 +969,7 @@ namespace Umbraco.Cms.Core.Services EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new ContentSavingNotification(content, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -1042,7 +1042,7 @@ namespace Umbraco.Cms.Core.Services EventMessages eventMessages = EventMessagesFactory.Get(); IContent[] contentsA = contents.ToArray(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new ContentSavingNotification(contentsA, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -1114,7 +1114,7 @@ namespace Umbraco.Cms.Core.Services throw new InvalidOperationException("Name cannot be more than 255 characters in length."); } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -1162,7 +1162,7 @@ namespace Umbraco.Cms.Core.Services throw new InvalidOperationException("Name cannot be more than 255 characters in length."); } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -1251,7 +1251,7 @@ namespace Umbraco.Cms.Core.Services return new PublishResult(PublishResultType.SuccessUnpublishAlready, evtMsgs, content); } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -1334,7 +1334,7 @@ namespace Umbraco.Cms.Core.Services internal PublishResult CommitDocumentChanges(IContent content, int userId = Constants.Security.SuperUserId) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages evtMsgs = EventMessagesFactory.Get(); @@ -1375,7 +1375,7 @@ namespace Umbraco.Cms.Core.Services /// saving/publishing, branch saving/publishing, etc... /// /// - private PublishResult CommitDocumentChangesInternal(IScope scope, IContent content, + private PublishResult CommitDocumentChangesInternal(ICoreScope scope, IContent content, EventMessages eventMessages, IReadOnlyCollection allLangs, IDictionary? notificationState, int userId = Constants.Security.SuperUserId, @@ -1705,7 +1705,7 @@ namespace Umbraco.Cms.Core.Services private void PerformScheduledPublishingExpiration(DateTime date, List results, EventMessages evtMsgs, Lazy> allLangs) { - using IScope scope = ScopeProvider.CreateScope(); + using ICoreScope scope = ScopeProvider.CreateCoreScope(); // do a fast read without any locks since this executes often to see if we even need to proceed if (_documentRepository.HasContentForExpiration(date)) @@ -1780,7 +1780,7 @@ namespace Umbraco.Cms.Core.Services private void PerformScheduledPublishingRelease(DateTime date, List results, EventMessages evtMsgs, Lazy> allLangs) { - using IScope scope = ScopeProvider.CreateScope(); + using ICoreScope scope = ScopeProvider.CreateCoreScope(); // do a fast read without any locks since this executes often to see if we even need to proceed if (_documentRepository.HasContentForRelease(date)) @@ -2074,7 +2074,7 @@ namespace Umbraco.Cms.Core.Services var results = new List(); var publishedDocuments = new List(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -2163,7 +2163,7 @@ namespace Umbraco.Cms.Core.Services // shouldPublish: a function determining whether the document has changes that need to be published // note - 'force' is handled by 'editing' // publishValues: a function publishing values (using the appropriate PublishCulture calls) - private PublishResult? SaveAndPublishBranchItem(IScope scope, IContent document, + private PublishResult? SaveAndPublishBranchItem(ICoreScope scope, IContent document, Func?> shouldPublish, Func, IReadOnlyCollection, bool> publishCultures, bool isRoot, @@ -2213,7 +2213,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { if (scope.Notifications.PublishCancelable(new ContentDeletingNotification(content, eventMessages))) { @@ -2243,7 +2243,7 @@ namespace Umbraco.Cms.Core.Services return OperationResult.Succeed(eventMessages); } - private void DeleteLocked(IScope scope, IContent content, EventMessages evtMsgs) + private void DeleteLocked(ICoreScope scope, IContent content, EventMessages evtMsgs) { void DoDelete(IContent c) { @@ -2285,7 +2285,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages evtMsgs = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var deletingVersionsNotification = new ContentDeletingVersionsNotification(id, evtMsgs, dateToRetain: versionDate); @@ -2320,7 +2320,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages evtMsgs = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var deletingVersionsNotification = new ContentDeletingVersionsNotification(id, evtMsgs, versionId); if (scope.Notifications.PublishCancelable(deletingVersionsNotification)) @@ -2362,7 +2362,7 @@ namespace Umbraco.Cms.Core.Services EventMessages eventMessages = EventMessagesFactory.Get(); var moves = new List<(IContent, string)>(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -2427,7 +2427,7 @@ namespace Umbraco.Cms.Core.Services var moves = new List<(IContent, string)>(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -2553,7 +2553,7 @@ namespace Umbraco.Cms.Core.Services var deleted = new List(); EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -2592,7 +2592,7 @@ namespace Umbraco.Cms.Core.Services public bool RecycleBinSmells() { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return _documentRepository.RecycleBinSmells(); @@ -2635,7 +2635,7 @@ namespace Umbraco.Cms.Core.Services IContent copy = content.DeepCloneWithResetIdentities(); copy.ParentId = parentId; - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { if (scope.Notifications.PublishCancelable( new ContentCopyingNotification(content, copy, parentId, eventMessages))) @@ -2761,7 +2761,7 @@ namespace Umbraco.Cms.Core.Services } EventMessages evtMsgs = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var sendingToPublishNotification = new ContentSendingToPublishNotification(content, evtMsgs); if (scope.Notifications.PublishCancelable(sendingToPublishNotification)) @@ -2829,7 +2829,7 @@ namespace Umbraco.Cms.Core.Services return new OperationResult(OperationResultType.NoOperation, evtMsgs); } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -2860,7 +2860,7 @@ namespace Umbraco.Cms.Core.Services return new OperationResult(OperationResultType.NoOperation, evtMsgs); } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); IContent[] itemsA = GetByIds(idsA).ToArray(); @@ -2871,7 +2871,7 @@ namespace Umbraco.Cms.Core.Services } } - private OperationResult Sort(IScope scope, IContent[] itemsA, int userId, EventMessages eventMessages) + private OperationResult Sort(ICoreScope scope, IContent[] itemsA, int userId, EventMessages eventMessages) { var sortingNotification = new ContentSortingNotification(itemsA, eventMessages); var savingNotification = new ContentSavingNotification(itemsA, eventMessages); @@ -2938,7 +2938,7 @@ namespace Umbraco.Cms.Core.Services public ContentDataIntegrityReport CheckDataIntegrity(ContentDataIntegrityReportOptions options) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.WriteLock(Constants.Locks.ContentTree); @@ -2970,7 +2970,7 @@ namespace Umbraco.Cms.Core.Services /// An Enumerable list of objects internal IEnumerable GetPublishedDescendants(IContent content) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); return GetPublishedDescendantsLocked(content).ToArray(); // ToArray important in uow! @@ -3033,7 +3033,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// - private PublishResult StrategyCanPublish(IScope scope, IContent content, bool checkPath, + private PublishResult StrategyCanPublish(ICoreScope scope, IContent content, bool checkPath, IReadOnlyList? culturesPublishing, IReadOnlyCollection? culturesUnpublishing, EventMessages evtMsgs, IReadOnlyCollection allLangs, IDictionary? notificationState) @@ -3257,7 +3257,7 @@ namespace Umbraco.Cms.Core.Services /// /// /// - private PublishResult StrategyCanUnpublish(IScope scope, IContent content, EventMessages evtMsgs) + private PublishResult StrategyCanUnpublish(ICoreScope scope, IContent content, EventMessages evtMsgs) { // raise Unpublishing notification if (scope.Notifications.PublishCancelable(new ContentUnpublishingNotification(content, evtMsgs))) @@ -3350,7 +3350,7 @@ namespace Umbraco.Cms.Core.Services // PerformMoveLocked and DeleteLocked that must be applied immediately, // no point queuing operations // - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -3426,7 +3426,7 @@ namespace Umbraco.Cms.Core.Services public void DeleteOfType(int contentTypeId, int userId = Constants.Security.SuperUserId) => DeleteOfTypes(new[] {contentTypeId}, userId); - private IContentType GetContentType(IScope scope, string contentTypeAlias) + private IContentType GetContentType(ICoreScope scope, string contentTypeAlias) { if (contentTypeAlias == null) { @@ -3466,7 +3466,7 @@ namespace Umbraco.Cms.Core.Services nameof(contentTypeAlias)); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return GetContentType(scope, contentTypeAlias); } @@ -3478,7 +3478,7 @@ namespace Umbraco.Cms.Core.Services public IContent? GetBlueprintById(int id) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); IContent? blueprint = _documentBlueprintRepository.Get(id); @@ -3493,7 +3493,7 @@ namespace Umbraco.Cms.Core.Services public IContent? GetBlueprintById(Guid id) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.ContentTree); IContent? blueprint = _documentBlueprintRepository.Get(id); @@ -3518,7 +3518,7 @@ namespace Umbraco.Cms.Core.Services content.Blueprint = true; - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); @@ -3544,7 +3544,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages evtMsgs = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); _documentBlueprintRepository.Delete(content); @@ -3574,7 +3574,7 @@ namespace Umbraco.Cms.Core.Services if (blueprint.CultureInfos?.Count > 0) { cultures = blueprint.CultureInfos.Values.Select(x => x.Culture); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { if (blueprint.CultureInfos.TryGetValue(_languageRepository.GetDefaultIsoCode(), out ContentCultureInfos defaultCulture)) @@ -3606,7 +3606,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable? GetBlueprintsForContentTypes(params int[] contentTypeId) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { IQuery query = Query(); if (contentTypeId.Length > 0) @@ -3627,7 +3627,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages evtMsgs = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.ContentTree); diff --git a/src/Umbraco.Core/Services/ContentTypeService.cs b/src/Umbraco.Core/Services/ContentTypeService.cs index 11dafd1464..8f7316d913 100644 --- a/src/Umbraco.Core/Services/ContentTypeService.cs +++ b/src/Umbraco.Core/Services/ContentTypeService.cs @@ -16,7 +16,7 @@ namespace Umbraco.Cms.Core.Services /// public class ContentTypeService : ContentTypeServiceBase, IContentTypeService { - public ContentTypeService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IContentService contentService, + public ContentTypeService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IContentService contentService, IContentTypeRepository repository, IAuditRepository auditRepository, IDocumentTypeContainerRepository entityContainerRepository, IEntityRepository entityRepository, IEventAggregator eventAggregator) : base(provider, loggerFactory, eventMessagesFactory, repository, auditRepository, entityContainerRepository, entityRepository, eventAggregator) @@ -74,7 +74,7 @@ namespace Umbraco.Cms.Core.Services protected override void DeleteItemsOfTypes(IEnumerable typeIds) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var typeIdsA = typeIds.ToArray(); ContentService.DeleteOfTypes(typeIdsA); @@ -90,7 +90,7 @@ namespace Umbraco.Cms.Core.Services /// Beware! Works across content, media and member types. public IEnumerable GetAllPropertyTypeAliases() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // that one is special because it works across content, media and member types scope.ReadLock(new[] { Constants.Locks.ContentTypes, Constants.Locks.MediaTypes, Constants.Locks.MemberTypes }); @@ -106,7 +106,7 @@ namespace Umbraco.Cms.Core.Services /// Beware! Works across content, media and member types. public IEnumerable GetAllContentTypeAliases(params Guid[] guids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // that one is special because it works across content, media and member types scope.ReadLock(new[] { Constants.Locks.ContentTypes, Constants.Locks.MediaTypes, Constants.Locks.MemberTypes }); @@ -122,7 +122,7 @@ namespace Umbraco.Cms.Core.Services /// Beware! Works across content, media and member types. public IEnumerable GetAllContentTypeIds(string[] aliases) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // that one is special because it works across content, media and member types scope.ReadLock(new[] { Constants.Locks.ContentTypes, Constants.Locks.MediaTypes, Constants.Locks.MemberTypes }); diff --git a/src/Umbraco.Core/Services/ContentTypeServiceBase.cs b/src/Umbraco.Core/Services/ContentTypeServiceBase.cs index 2aa8f0268f..1e97e02dca 100644 --- a/src/Umbraco.Core/Services/ContentTypeServiceBase.cs +++ b/src/Umbraco.Core/Services/ContentTypeServiceBase.cs @@ -6,7 +6,7 @@ namespace Umbraco.Cms.Core.Services { public abstract class ContentTypeServiceBase : RepositoryService { - protected ContentTypeServiceBase(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory) + protected ContentTypeServiceBase(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory) : base(provider, loggerFactory, eventMessagesFactory) { } } diff --git a/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs b/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs index 9a38b55b83..8c97ff5a2d 100644 --- a/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs +++ b/src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Core.Services private readonly IEntityRepository _entityRepository; private readonly IEventAggregator _eventAggregator; - protected ContentTypeServiceBase(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + protected ContentTypeServiceBase(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, TRepository repository, IAuditRepository auditRepository, IEntityContainerRepository? containerRepository, IEntityRepository entityRepository, IEventAggregator eventAggregator) : base(provider, loggerFactory, eventMessagesFactory) @@ -73,7 +73,7 @@ namespace Umbraco.Cms.Core.Services { try { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); ValidateLocked(compo!); @@ -263,7 +263,7 @@ namespace Umbraco.Cms.Core.Services public TItem? Get(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); return Repository.Get(id); @@ -272,7 +272,7 @@ namespace Umbraco.Cms.Core.Services public TItem? Get(string alias) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); return Repository.Get(alias); @@ -281,7 +281,7 @@ namespace Umbraco.Cms.Core.Services public TItem? Get(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); return Repository.Get(id); @@ -290,7 +290,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAll(params int[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); return Repository.GetMany(ids); @@ -304,7 +304,8 @@ namespace Umbraco.Cms.Core.Services return Enumerable.Empty(); } - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) + { scope.ReadLock(ReadLockIds); return Repository.GetMany(ids.ToArray()); @@ -313,7 +314,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable? GetChildren(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); var query = Query().Where(x => x.ParentId == id); @@ -323,7 +324,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable? GetChildren(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); var found = Get(id); @@ -335,7 +336,7 @@ namespace Umbraco.Cms.Core.Services public bool HasChildren(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); var query = Query().Where(x => x.ParentId == id); @@ -346,7 +347,7 @@ namespace Umbraco.Cms.Core.Services public bool HasChildren(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); var found = Get(id); @@ -364,7 +365,7 @@ namespace Umbraco.Cms.Core.Services /// public bool HasContainerInPath(string contentPath) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // can use same repo for both content and media return Repository.HasContainerInPath(contentPath); @@ -373,7 +374,7 @@ namespace Umbraco.Cms.Core.Services public bool HasContainerInPath(params int[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // can use same repo for both content and media return Repository.HasContainerInPath(ids); @@ -382,7 +383,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetDescendants(int id, bool andSelf) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); @@ -434,7 +435,7 @@ namespace Umbraco.Cms.Core.Services public int Count() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); return Repository.Count(Query()); @@ -443,7 +444,7 @@ namespace Umbraco.Cms.Core.Services public bool HasContentNodes(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); return Repository.HasContentNodes(id); @@ -461,7 +462,8 @@ namespace Umbraco.Cms.Core.Services return; } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) + { EventMessages eventMessages = EventMessagesFactory.Get(); SavingNotification savingNotification = GetSavingNotification(item, eventMessages); @@ -515,7 +517,7 @@ namespace Umbraco.Cms.Core.Services { TItem[] itemsA = items.ToArray(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); SavingNotification savingNotification = GetSavingNotification(itemsA, eventMessages); @@ -566,7 +568,7 @@ namespace Umbraco.Cms.Core.Services public void Delete(TItem item, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); DeletingNotification deletingNotification = GetDeletingNotification(item, eventMessages); @@ -634,7 +636,7 @@ namespace Umbraco.Cms.Core.Services { TItem[] itemsA = items.ToArray(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); DeletingNotification deletingNotification = GetDeletingNotification(itemsA, eventMessages); @@ -752,7 +754,7 @@ namespace Umbraco.Cms.Core.Services var evtMsgs = EventMessagesFactory.Get(); TItem copy; - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(WriteLockIds); @@ -805,7 +807,7 @@ namespace Umbraco.Cms.Core.Services EventMessages eventMessages = EventMessagesFactory.Get(); var moveInfo = new List>(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var moveEventInfo = new MoveEventInfo(moving, moving.Path, containerId); MovingNotification movingNotification = GetMovingNotification(moveEventInfo, eventMessages); @@ -857,7 +859,7 @@ namespace Umbraco.Cms.Core.Services public Attempt?> CreateContainer(int parentId, Guid key, string name, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(WriteLockIds); // also for containers @@ -913,7 +915,7 @@ namespace Umbraco.Cms.Core.Services return OperationResult.Attempt.Fail(eventMessages, ex); } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new EntityContainerSavingNotification(container, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -939,7 +941,7 @@ namespace Umbraco.Cms.Core.Services public EntityContainer? GetContainer(int containerId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); // also for containers @@ -949,7 +951,7 @@ namespace Umbraco.Cms.Core.Services public EntityContainer? GetContainer(Guid containerId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); // also for containers @@ -959,7 +961,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable? GetContainers(int[] containerIds) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); // also for containers @@ -984,7 +986,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable? GetContainers(string name, int level) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); // also for containers @@ -995,7 +997,7 @@ namespace Umbraco.Cms.Core.Services public Attempt DeleteContainer(int containerId, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(WriteLockIds); // also for containers @@ -1036,7 +1038,7 @@ namespace Umbraco.Cms.Core.Services public Attempt?> RenameContainer(int id, string name, int userId = Cms.Core.Constants.Security.SuperUserId) { EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(WriteLockIds); // also for containers diff --git a/src/Umbraco.Core/Services/ContentVersionService.cs b/src/Umbraco.Core/Services/ContentVersionService.cs index aa278324eb..9e32bab762 100644 --- a/src/Umbraco.Core/Services/ContentVersionService.cs +++ b/src/Umbraco.Core/Services/ContentVersionService.cs @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Services private readonly ILogger _logger; private readonly IDocumentVersionRepository _documentVersionRepository; private readonly IContentVersionCleanupPolicy _contentVersionCleanupPolicy; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IEventMessagesFactory _eventMessagesFactory; private readonly IAuditRepository _auditRepository; private readonly ILanguageRepository _languageRepository; @@ -26,7 +26,7 @@ namespace Umbraco.Cms.Core.Services ILogger logger, IDocumentVersionRepository documentVersionRepository, IContentVersionCleanupPolicy contentVersionCleanupPolicy, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IEventMessagesFactory eventMessagesFactory, IAuditRepository auditRepository, ILanguageRepository languageRepository) @@ -78,7 +78,7 @@ namespace Umbraco.Cms.Core.Services * * tl;dr lots of scopes to enable other connections to use the DB whilst we work. */ - using (IScope scope = _scopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { IReadOnlyCollection? allHistoricVersions = _documentVersionRepository.GetDocumentVersionsEligibleForCleanup(); @@ -115,7 +115,7 @@ namespace Umbraco.Cms.Core.Services foreach (IEnumerable group in versionsToDelete.InGroupsOf(Constants.Sql.MaxParameterCount)) { - using (IScope scope = _scopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { scope.WriteLock(Constants.Locks.ContentTree); var groupEnumerated = group.ToList(); @@ -130,7 +130,7 @@ namespace Umbraco.Cms.Core.Services } } - using (_scopeProvider.CreateScope(autoComplete: true)) + using (_scopeProvider.CreateCoreScope(autoComplete: true)) { Audit(AuditType.Delete, Constants.Security.SuperUserId, -1, $"Removed {versionsToDelete.Count} ContentVersion(s) according to cleanup policy"); } @@ -151,7 +151,7 @@ namespace Umbraco.Cms.Core.Services throw new ArgumentOutOfRangeException(nameof(pageSize)); } - using (IScope scope = _scopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { var languageId = _languageRepository.GetIdByIsoCode(culture, throwOnNotFound: true); scope.ReadLock(Constants.Locks.ContentTree); @@ -162,7 +162,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetPreventCleanup(int versionId, bool preventCleanup, int userId = -1) { - using (IScope scope = _scopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { scope.WriteLock(Constants.Locks.ContentTree); _documentVersionRepository.SetPreventCleanup(versionId, preventCleanup); diff --git a/src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs b/src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs index 9789d169ad..810106e0ba 100644 --- a/src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs +++ b/src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs @@ -13,10 +13,10 @@ namespace Umbraco.Cms.Core.Services public class DefaultContentVersionCleanupPolicy : IContentVersionCleanupPolicy { private readonly IOptions _contentSettings; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IDocumentVersionRepository _documentVersionRepository; - public DefaultContentVersionCleanupPolicy(IOptions contentSettings, IScopeProvider scopeProvider, IDocumentVersionRepository documentVersionRepository) + public DefaultContentVersionCleanupPolicy(IOptions contentSettings, ICoreScopeProvider scopeProvider, IDocumentVersionRepository documentVersionRepository) { _contentSettings = contentSettings ?? throw new ArgumentNullException(nameof(contentSettings)); _scopeProvider = scopeProvider ?? throw new ArgumentNullException(nameof(scopeProvider)); @@ -32,7 +32,7 @@ namespace Umbraco.Cms.Core.Services var theRest = new List(); - using(_scopeProvider.CreateScope(autoComplete: true)) + using(_scopeProvider.CreateCoreScope(autoComplete: true)) { var policyOverrides = _documentVersionRepository.GetCleanupPolicies()? .ToDictionary(x => x.ContentTypeId); diff --git a/src/Umbraco.Core/Services/DomainService.cs b/src/Umbraco.Core/Services/DomainService.cs index 2829368fa2..b319f0fc42 100644 --- a/src/Umbraco.Core/Services/DomainService.cs +++ b/src/Umbraco.Core/Services/DomainService.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Services { private readonly IDomainRepository _domainRepository; - public DomainService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public DomainService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IDomainRepository domainRepository) : base(provider, loggerFactory, eventMessagesFactory) { @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.Services public bool Exists(string domainName) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _domainRepository.Exists(domainName); } @@ -31,7 +31,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var deletingNotification = new DomainDeletingNotification(domain, eventMessages); if (scope.Notifications.PublishCancelable(deletingNotification)) @@ -51,7 +51,7 @@ namespace Umbraco.Cms.Core.Services public IDomain? GetByName(string name) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _domainRepository.GetByName(name); } @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Core.Services public IDomain? GetById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _domainRepository.Get(id); } @@ -67,7 +67,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAll(bool includeWildcards) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _domainRepository.GetAll(includeWildcards); } @@ -75,7 +75,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAssignedDomains(int contentId, bool includeWildcards) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _domainRepository.GetAssignedDomains(contentId, includeWildcards); } @@ -85,7 +85,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new DomainSavingNotification(domainEntity, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) diff --git a/src/Umbraco.Core/Services/EntityService.cs b/src/Umbraco.Core/Services/EntityService.cs index 69f705ffee..5fa7ed24f7 100644 --- a/src/Umbraco.Core/Services/EntityService.cs +++ b/src/Umbraco.Core/Services/EntityService.cs @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Core.Services private IQuery? _queryRootEntity; private readonly IIdKeyMap _idKeyMap; - public EntityService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IIdKeyMap idKeyMap, IEntityRepository entityRepository) + public EntityService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IIdKeyMap idKeyMap, IEntityRepository entityRepository) : base(provider, loggerFactory, eventMessagesFactory) { _idKeyMap = idKeyMap; @@ -57,7 +57,7 @@ namespace Umbraco.Cms.Core.Services /// public IEntitySlim? Get(int id) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.Get(id); } @@ -66,7 +66,7 @@ namespace Umbraco.Cms.Core.Services /// public IEntitySlim? Get(Guid key) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.Get(key); } @@ -75,7 +75,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual IEntitySlim? Get(int id, UmbracoObjectTypes objectType) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.Get(id, objectType.GetGuid()); } @@ -84,7 +84,7 @@ namespace Umbraco.Cms.Core.Services /// public IEntitySlim? Get(Guid key, UmbracoObjectTypes objectType) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.Get(key, objectType.GetGuid()); } @@ -94,7 +94,7 @@ namespace Umbraco.Cms.Core.Services public virtual IEntitySlim? Get(int id) where T : IUmbracoEntity { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.Get(id); } @@ -104,7 +104,7 @@ namespace Umbraco.Cms.Core.Services public virtual IEntitySlim? Get(Guid key) where T : IUmbracoEntity { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.Get(key); } @@ -113,7 +113,7 @@ namespace Umbraco.Cms.Core.Services /// public bool Exists(int id) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.Exists(id); } @@ -122,7 +122,7 @@ namespace Umbraco.Cms.Core.Services /// public bool Exists(Guid key) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.Exists(key); } @@ -141,7 +141,7 @@ namespace Umbraco.Cms.Core.Services var objectType = GetObjectType(entityType); var objectTypeId = objectType.GetGuid(); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetAll(objectTypeId, ids); } @@ -160,7 +160,7 @@ namespace Umbraco.Cms.Core.Services GetObjectType(entityType); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetAll(objectType.GetGuid(), ids); } @@ -176,7 +176,7 @@ namespace Umbraco.Cms.Core.Services var entityType = ObjectTypes.GetClrType(objectType); GetObjectType(entityType); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetAll(objectType, ids); } @@ -190,7 +190,7 @@ namespace Umbraco.Cms.Core.Services var objectType = GetObjectType(entityType); var objectTypeId = objectType.GetGuid(); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetAll(objectTypeId, keys); } @@ -202,7 +202,7 @@ namespace Umbraco.Cms.Core.Services var entityType = objectType.GetClrType(); GetObjectType(entityType); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetAll(objectType.GetGuid(), keys); } @@ -214,7 +214,7 @@ namespace Umbraco.Cms.Core.Services var entityType = ObjectTypes.GetClrType(objectType); GetObjectType(entityType); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetAll(objectType, keys); } @@ -223,7 +223,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual IEnumerable GetRootEntities(UmbracoObjectTypes objectType) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetByQuery(QueryRootEntity, objectType.GetGuid()); } @@ -232,7 +232,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual IEntitySlim? GetParent(int id) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var entity = _entityRepository.Get(id); if (entity is null || entity.ParentId == -1 || entity.ParentId == -20 || entity.ParentId == -21) @@ -244,7 +244,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual IEntitySlim? GetParent(int id, UmbracoObjectTypes objectType) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var entity = _entityRepository.Get(id); if (entity is null || entity.ParentId == -1 || entity.ParentId == -20 || entity.ParentId == -21) @@ -256,7 +256,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual IEnumerable GetChildren(int parentId) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == parentId); return _entityRepository.GetByQuery(query); @@ -266,7 +266,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual IEnumerable GetChildren(int parentId, UmbracoObjectTypes objectType) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == parentId); return _entityRepository.GetByQuery(query, objectType.GetGuid()); @@ -276,7 +276,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual IEnumerable GetDescendants(int id) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var entity = _entityRepository.Get(id); var pathMatch = entity?.Path + ","; @@ -288,7 +288,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual IEnumerable GetDescendants(int id, UmbracoObjectTypes objectType) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var entity = _entityRepository.Get(id); if (entity is null) @@ -304,7 +304,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetPagedChildren(int id, UmbracoObjectTypes objectType, long pageIndex, int pageSize, out long totalRecords, IQuery? filter = null, Ordering? ordering = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == id && x.Trashed == false); @@ -316,7 +316,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetPagedDescendants(int id, UmbracoObjectTypes objectType, long pageIndex, int pageSize, out long totalRecords, IQuery? filter = null, Ordering? ordering = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var objectTypeGuid = objectType.GetGuid(); var query = Query(); @@ -348,7 +348,7 @@ namespace Umbraco.Cms.Core.Services if (idsA.Length == 0) return Enumerable.Empty(); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var objectTypeGuid = objectType.GetGuid(); var query = Query(); @@ -385,7 +385,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetPagedDescendants(UmbracoObjectTypes objectType, long pageIndex, int pageSize, out long totalRecords, IQuery? filter = null, Ordering? ordering = null, bool includeTrashed = true) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query(); if (includeTrashed == false) @@ -398,7 +398,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual UmbracoObjectTypes GetObjectType(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetObjectType(id); } @@ -407,7 +407,7 @@ namespace Umbraco.Cms.Core.Services /// public virtual UmbracoObjectTypes GetObjectType(Guid key) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetObjectType(key); } @@ -452,7 +452,7 @@ namespace Umbraco.Cms.Core.Services var entityType = objectType.GetClrType(); GetObjectType(entityType); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetAllPaths(objectType.GetGuid(), ids); } @@ -464,7 +464,7 @@ namespace Umbraco.Cms.Core.Services var entityType = objectType.GetClrType(); GetObjectType(entityType); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.GetAllPaths(objectType.GetGuid(), keys); } @@ -473,7 +473,7 @@ namespace Umbraco.Cms.Core.Services /// public int ReserveId(Guid key) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _entityRepository.ReserveId(key); } diff --git a/src/Umbraco.Core/Services/ExternalLoginService.cs b/src/Umbraco.Core/Services/ExternalLoginService.cs index 1e8d25b8e8..4fde36ad37 100644 --- a/src/Umbraco.Core/Services/ExternalLoginService.cs +++ b/src/Umbraco.Core/Services/ExternalLoginService.cs @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Services { private readonly IExternalLoginWithKeyRepository _externalLoginRepository; - public ExternalLoginService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public ExternalLoginService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IExternalLoginWithKeyRepository externalLoginRepository) : base(provider, loggerFactory, eventMessagesFactory) { @@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Services } [Obsolete("Use ctor injecting IExternalLoginWithKeyRepository")] - public ExternalLoginService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public ExternalLoginService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IExternalLoginRepository externalLoginRepository) : this(provider, loggerFactory, eventMessagesFactory, StaticServiceProvider.Instance.GetRequiredService()) { @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetExternalLogins(Guid userOrMemberKey) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _externalLoginRepository.Get(Query().Where(x => x.Key == userOrMemberKey))? .ToList(); @@ -69,7 +69,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetExternalLoginTokens(Guid userOrMemberKey) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _externalLoginRepository.Get(Query().Where(x => x.Key == userOrMemberKey))? .ToList(); @@ -79,7 +79,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? Find(string loginProvider, string providerKey) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _externalLoginRepository.Get(Query() .Where(x => x.ProviderKey == providerKey && x.LoginProvider == loginProvider))? @@ -90,7 +90,7 @@ namespace Umbraco.Cms.Core.Services /// public void Save(Guid userOrMemberKey, IEnumerable logins) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _externalLoginRepository.Save(userOrMemberKey, logins); scope.Complete(); @@ -100,7 +100,7 @@ namespace Umbraco.Cms.Core.Services /// public void Save(Guid userOrMemberKey, IEnumerable tokens) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _externalLoginRepository.Save(userOrMemberKey, tokens); scope.Complete(); @@ -110,7 +110,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteUserLogins(Guid userOrMemberKey) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _externalLoginRepository.DeleteUserLogins(userOrMemberKey); scope.Complete(); diff --git a/src/Umbraco.Core/Services/FileService.cs b/src/Umbraco.Core/Services/FileService.cs index 009059916a..3a2e0e1168 100644 --- a/src/Umbraco.Core/Services/FileService.cs +++ b/src/Umbraco.Core/Services/FileService.cs @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Core.Services private const string PartialViewHeader = "@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage"; private const string PartialViewMacroHeader = "@inherits Umbraco.Cms.Web.Common.Macros.PartialViewMacroPage"; - public FileService(IScopeProvider uowProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public FileService(ICoreScopeProvider uowProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, ITemplateRepository templateRepository, IPartialViewRepository partialViewRepository, IPartialViewMacroRepository partialViewMacroRepository, IAuditRepository auditRepository, IShortStringHelper shortStringHelper, IOptions globalSettings, IHostingEnvironment hostingEnvironment) @@ -58,7 +58,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetStylesheets(params string[] paths) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _stylesheetRepository.GetMany(paths); } @@ -67,7 +67,7 @@ namespace Umbraco.Cms.Core.Services /// public IStylesheet? GetStylesheet(string? path) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _stylesheetRepository.Get(path); } @@ -81,7 +81,8 @@ namespace Umbraco.Cms.Core.Services return; } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) + { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new StylesheetSavingNotification(stylesheet, eventMessages); @@ -103,7 +104,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteStylesheet(string path, int? userId) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { IStylesheet? stylesheet = _stylesheetRepository.Get(path); if (stylesheet == null) @@ -133,7 +134,7 @@ namespace Umbraco.Cms.Core.Services /// public void CreateStyleSheetFolder(string folderPath) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _stylesheetRepository.AddFolder(folderPath); scope.Complete(); @@ -143,7 +144,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteStyleSheetFolder(string folderPath) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _stylesheetRepository.DeleteFolder(folderPath); scope.Complete(); @@ -153,7 +154,7 @@ namespace Umbraco.Cms.Core.Services /// public Stream? GetStylesheetFileContentStream(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _stylesheetRepository.GetFileContentStream(filepath); } @@ -162,7 +163,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetStylesheetFileContent(string filepath, Stream content) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _stylesheetRepository.SetFileContent(filepath, content); scope.Complete(); @@ -172,7 +173,7 @@ namespace Umbraco.Cms.Core.Services /// public long GetStylesheetFileSize(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _stylesheetRepository.GetFileSize(filepath); } @@ -185,7 +186,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetScripts(params string[] names) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _scriptRepository.GetMany(names); } @@ -194,7 +195,7 @@ namespace Umbraco.Cms.Core.Services /// public IScript? GetScript(string? name) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _scriptRepository.Get(name); } @@ -212,7 +213,8 @@ namespace Umbraco.Cms.Core.Services return; } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) + { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new ScriptSavingNotification(script, eventMessages); @@ -233,7 +235,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteScript(string path, int? userId = null) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { IScript? script = _scriptRepository.Get(path); if (script == null) @@ -262,7 +264,7 @@ namespace Umbraco.Cms.Core.Services /// public void CreateScriptFolder(string folderPath) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _scriptRepository.AddFolder(folderPath); scope.Complete(); @@ -272,7 +274,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteScriptFolder(string folderPath) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _scriptRepository.DeleteFolder(folderPath); scope.Complete(); @@ -282,7 +284,7 @@ namespace Umbraco.Cms.Core.Services /// public Stream? GetScriptFileContentStream(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _scriptRepository.GetFileContentStream(filepath); } @@ -291,7 +293,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetScriptFileContent(string filepath, Stream content) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _scriptRepository.SetFileContent(filepath, content); scope.Complete(); @@ -301,7 +303,7 @@ namespace Umbraco.Cms.Core.Services /// public long GetScriptFileSize(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _scriptRepository.GetFileSize(filepath); } @@ -344,7 +346,7 @@ namespace Umbraco.Cms.Core.Services template.Content = content; } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingEvent = new TemplateSavingNotification(template, eventMessages, true, contentTypeAlias!); if (scope.Notifications.PublishCancelable(savingEvent)) @@ -411,7 +413,7 @@ namespace Umbraco.Cms.Core.Services /// An enumerable list of objects public IEnumerable? GetTemplates(params string[] aliases) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _templateRepository.GetAll(aliases)?.OrderBy(x => x.Name); } @@ -423,7 +425,7 @@ namespace Umbraco.Cms.Core.Services /// An enumerable list of objects public IEnumerable? GetTemplates(int masterTemplateId) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _templateRepository.GetChildren(masterTemplateId)?.OrderBy(x => x.Name); } @@ -436,7 +438,7 @@ namespace Umbraco.Cms.Core.Services /// The object matching the alias, or null. public ITemplate? GetTemplate(string? alias) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _templateRepository.Get(alias); } @@ -449,7 +451,7 @@ namespace Umbraco.Cms.Core.Services /// The object matching the identifier, or null. public ITemplate? GetTemplate(int id) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _templateRepository.Get(id); } @@ -462,7 +464,7 @@ namespace Umbraco.Cms.Core.Services /// The object matching the identifier, or null. public ITemplate? GetTemplate(Guid id) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { IQuery? query = Query().Where(x => x.Key == id); return _templateRepository.Get(query)?.SingleOrDefault(); @@ -476,7 +478,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTemplateDescendants(int masterTemplateId) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _templateRepository.GetDescendants(masterTemplateId); } @@ -500,7 +502,7 @@ namespace Umbraco.Cms.Core.Services } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new TemplateSavingNotification(template, eventMessages); @@ -527,7 +529,7 @@ namespace Umbraco.Cms.Core.Services public void SaveTemplate(IEnumerable templates, int userId = Constants.Security.SuperUserId) { ITemplate[] templatesA = templates.ToArray(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new TemplateSavingNotification(templatesA, eventMessages); @@ -556,7 +558,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteTemplate(string alias, int userId = Constants.Security.SuperUserId) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { ITemplate? template = _templateRepository.Get(alias); if (template == null) @@ -609,7 +611,7 @@ namespace Umbraco.Cms.Core.Services /// public Stream? GetTemplateFileContentStream(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _templateRepository.GetFileContentStream(filepath); } @@ -618,7 +620,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetTemplateFileContent(string filepath, Stream content) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _templateRepository.SetFileContent(filepath, content); scope.Complete(); @@ -628,7 +630,7 @@ namespace Umbraco.Cms.Core.Services /// public long GetTemplateFileSize(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _templateRepository.GetFileSize(filepath); } @@ -656,7 +658,7 @@ namespace Umbraco.Cms.Core.Services public void DeletePartialViewFolder(string folderPath) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _partialViewRepository.DeleteFolder(folderPath); scope.Complete(); @@ -665,7 +667,7 @@ namespace Umbraco.Cms.Core.Services public void DeletePartialViewMacroFolder(string folderPath) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _partialViewMacroRepository.DeleteFolder(folderPath); scope.Complete(); @@ -674,7 +676,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetPartialViews(params string[] names) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _partialViewRepository.GetMany(names); } @@ -682,7 +684,7 @@ namespace Umbraco.Cms.Core.Services public IPartialView? GetPartialView(string path) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _partialViewRepository.Get(path); } @@ -690,7 +692,7 @@ namespace Umbraco.Cms.Core.Services public IPartialView? GetPartialViewMacro(string path) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _partialViewMacroRepository.Get(path); } @@ -744,7 +746,7 @@ namespace Umbraco.Cms.Core.Services } } - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var creatingNotification = new PartialViewCreatingNotification(partialView, eventMessages); @@ -780,7 +782,7 @@ namespace Umbraco.Cms.Core.Services private bool DeletePartialViewMacro(string path, PartialViewType partialViewType, int? userId = null) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { IPartialViewRepository repository = GetPartialViewRepository(partialViewType); @@ -818,7 +820,7 @@ namespace Umbraco.Cms.Core.Services private Attempt SavePartialView(IPartialView partialView, PartialViewType partialViewType, int? userId = null) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new PartialViewSavingNotification(partialView, eventMessages); @@ -862,7 +864,7 @@ namespace Umbraco.Cms.Core.Services public void CreatePartialViewFolder(string folderPath) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _partialViewRepository.AddFolder(folderPath); scope.Complete(); @@ -871,7 +873,7 @@ namespace Umbraco.Cms.Core.Services public void CreatePartialViewMacroFolder(string folderPath) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _partialViewMacroRepository.AddFolder(folderPath); scope.Complete(); @@ -894,7 +896,7 @@ namespace Umbraco.Cms.Core.Services /// public Stream? GetPartialViewFileContentStream(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _partialViewRepository.GetFileContentStream(filepath); } @@ -903,7 +905,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetPartialViewFileContent(string filepath, Stream content) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _partialViewRepository.SetFileContent(filepath, content); scope.Complete(); @@ -913,7 +915,7 @@ namespace Umbraco.Cms.Core.Services /// public long GetPartialViewFileSize(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _partialViewRepository.GetFileSize(filepath); } @@ -922,7 +924,7 @@ namespace Umbraco.Cms.Core.Services /// public Stream? GetPartialViewMacroFileContentStream(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _partialViewMacroRepository.GetFileContentStream(filepath); } @@ -931,7 +933,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetPartialViewMacroFileContent(string filepath, Stream content) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _partialViewMacroRepository.SetFileContent(filepath, content); scope.Complete(); @@ -941,7 +943,7 @@ namespace Umbraco.Cms.Core.Services /// public long GetPartialViewMacroFileSize(string filepath) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _partialViewMacroRepository.GetFileSize(filepath); } diff --git a/src/Umbraco.Core/Services/KeyValueService.cs b/src/Umbraco.Core/Services/KeyValueService.cs index 6c09272c42..834c0d3116 100644 --- a/src/Umbraco.Core/Services/KeyValueService.cs +++ b/src/Umbraco.Core/Services/KeyValueService.cs @@ -8,10 +8,10 @@ namespace Umbraco.Cms.Core.Services { internal class KeyValueService : IKeyValueService { - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IKeyValueRepository _repository; - public KeyValueService(IScopeProvider scopeProvider, IKeyValueRepository repository) + public KeyValueService(ICoreScopeProvider scopeProvider, IKeyValueRepository repository) { _scopeProvider = scopeProvider; _repository = repository; @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Core.Services /// public string? GetValue(string key) { - using (var scope = _scopeProvider.CreateScope(autoComplete: true)) + using (var scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { return _repository.Get(key)?.Value; } @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.Services /// public IReadOnlyDictionary? FindByKeyPrefix(string keyPrefix) { - using (var scope = _scopeProvider.CreateScope(autoComplete: true)) + using (var scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { return _repository.FindByKeyPrefix(keyPrefix); } @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Core.Services /// public void SetValue(string key, string value) { - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.KeyValues); @@ -74,7 +74,7 @@ namespace Umbraco.Cms.Core.Services /// public bool TrySetValue(string key, string originalValue, string newValue) { - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.KeyValues); diff --git a/src/Umbraco.Core/Services/LocalizationService.cs b/src/Umbraco.Core/Services/LocalizationService.cs index 4b44ee7d9a..ac9d800cb1 100644 --- a/src/Umbraco.Core/Services/LocalizationService.cs +++ b/src/Umbraco.Core/Services/LocalizationService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.Services private readonly IAuditRepository _auditRepository; public LocalizationService( - IScopeProvider provider, + ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IDictionaryRepository dictionaryRepository, @@ -82,7 +82,7 @@ namespace Umbraco.Cms.Core.Services /// public IDictionaryItem CreateDictionaryItemWithIdentity(string key, Guid? parentId, string? defaultValue = null) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { //validate the parent @@ -133,7 +133,7 @@ namespace Umbraco.Cms.Core.Services /// public IDictionaryItem? GetDictionaryItemById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var item = _dictionaryRepository.Get(id); //ensure the lazy Language callback is assigned @@ -149,7 +149,7 @@ namespace Umbraco.Cms.Core.Services /// public IDictionaryItem? GetDictionaryItemById(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var item = _dictionaryRepository.Get(id); //ensure the lazy Language callback is assigned @@ -165,7 +165,7 @@ namespace Umbraco.Cms.Core.Services /// public IDictionaryItem? GetDictionaryItemByKey(string key) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var item = _dictionaryRepository.Get(key); //ensure the lazy Language callback is assigned @@ -181,7 +181,7 @@ namespace Umbraco.Cms.Core.Services /// An enumerable list of objects public IEnumerable? GetDictionaryItemChildren(Guid parentId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == parentId); var items = _dictionaryRepository.Get(query)?.ToArray(); @@ -203,7 +203,7 @@ namespace Umbraco.Cms.Core.Services /// An enumerable list of objects public IEnumerable GetDictionaryItemDescendants(Guid? parentId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var items = _dictionaryRepository.GetDictionaryItemDescendants(parentId).ToArray(); //ensure the lazy Language callback is assigned @@ -219,7 +219,7 @@ namespace Umbraco.Cms.Core.Services /// An enumerable list of objects public IEnumerable? GetRootDictionaryItems() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == null); var items = _dictionaryRepository.Get(query)?.ToArray(); @@ -240,7 +240,7 @@ namespace Umbraco.Cms.Core.Services /// True if a exists, otherwise false public bool DictionaryItemExists(string key) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var item = _dictionaryRepository.Get(key); return item != null; @@ -254,7 +254,7 @@ namespace Umbraco.Cms.Core.Services /// Optional id of the user saving the dictionary item public void Save(IDictionaryItem dictionaryItem, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new DictionaryItemSavingNotification(dictionaryItem, eventMessages); @@ -285,7 +285,7 @@ namespace Umbraco.Cms.Core.Services /// Optional id of the user deleting the dictionary item public void Delete(IDictionaryItem dictionaryItem, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var deletingNotification = new DictionaryItemDeletingNotification(dictionaryItem, eventMessages); @@ -311,7 +311,7 @@ namespace Umbraco.Cms.Core.Services /// public ILanguage? GetLanguageById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _languageRepository.Get(id); } @@ -328,7 +328,8 @@ namespace Umbraco.Cms.Core.Services { return null; } - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _languageRepository.GetByIsoCode(isoCode); } @@ -337,7 +338,7 @@ namespace Umbraco.Cms.Core.Services /// public int? GetLanguageIdByIsoCode(string isoCode) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _languageRepository.GetIdByIsoCode(isoCode); } @@ -346,7 +347,7 @@ namespace Umbraco.Cms.Core.Services /// public string? GetLanguageIsoCodeById(int id) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _languageRepository.GetIsoCodeById(id); } @@ -355,7 +356,7 @@ namespace Umbraco.Cms.Core.Services /// public string GetDefaultLanguageIsoCode() { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _languageRepository.GetDefaultIsoCode(); } @@ -364,7 +365,7 @@ namespace Umbraco.Cms.Core.Services /// public int? GetDefaultLanguageId() { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _languageRepository.GetDefaultId(); } @@ -376,7 +377,7 @@ namespace Umbraco.Cms.Core.Services /// An enumerable list of objects public IEnumerable GetAllLanguages() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _languageRepository.GetMany(); } @@ -389,7 +390,7 @@ namespace Umbraco.Cms.Core.Services /// Optional id of the user saving the language public void Save(ILanguage language, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { // write-lock languages to guard against race conds when dealing with default language scope.WriteLock(Cms.Core.Constants.Locks.Languages); @@ -442,7 +443,7 @@ namespace Umbraco.Cms.Core.Services /// Optional id of the user deleting the language public void Delete(ILanguage language, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { // write-lock languages to guard against race conds when dealing with default language scope.WriteLock(Cms.Core.Constants.Locks.Languages); @@ -492,7 +493,7 @@ namespace Umbraco.Cms.Core.Services public Dictionary GetDictionaryItemKeyMap() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _dictionaryRepository.GetDictionaryItemKeyMap(); } diff --git a/src/Umbraco.Core/Services/MacroService.cs b/src/Umbraco.Core/Services/MacroService.cs index e4f58e5d60..6b598921e1 100644 --- a/src/Umbraco.Core/Services/MacroService.cs +++ b/src/Umbraco.Core/Services/MacroService.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Services private readonly IMacroRepository _macroRepository; private readonly IAuditRepository _auditRepository; - public MacroService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMacroRepository macroRepository, IAuditRepository auditRepository) + public MacroService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMacroRepository macroRepository, IAuditRepository auditRepository) : base(provider, loggerFactory, eventMessagesFactory) { _macroRepository = macroRepository; @@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.Services return GetAll().FirstOrDefault(x => x.Alias == alias); } - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return macroWithAliasRepository.GetByAlias(alias); } @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAll(params int[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _macroRepository.GetMany(ids); } @@ -58,7 +58,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAll(params Guid[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _macroRepository.GetMany(ids); } @@ -72,7 +72,7 @@ namespace Umbraco.Cms.Core.Services return GetAll().Where(x => hashset.Contains(x.Alias)); } - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return macroWithAliasRepository.GetAllByAlias(aliases) ?? Enumerable.Empty(); } @@ -80,7 +80,7 @@ namespace Umbraco.Cms.Core.Services public IMacro? GetById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _macroRepository.Get(id); } @@ -88,7 +88,7 @@ namespace Umbraco.Cms.Core.Services public IMacro? GetById(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _macroRepository.Get(id); } @@ -101,7 +101,7 @@ namespace Umbraco.Cms.Core.Services /// Optional id of the user deleting the macro public void Delete(IMacro macro, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var deletingNotification = new MacroDeletingNotification(macro, eventMessages); @@ -127,7 +127,7 @@ namespace Umbraco.Cms.Core.Services /// Optional Id of the user deleting the macro public void Save(IMacro macro, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new MacroSavingNotification(macro, eventMessages); diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs index dc5d171109..f9a47cf1ba 100644 --- a/src/Umbraco.Core/Services/MediaService.cs +++ b/src/Umbraco.Core/Services/MediaService.cs @@ -33,7 +33,7 @@ namespace Umbraco.Cms.Core.Services #region Constructors - public MediaService(IScopeProvider provider, MediaFileManager mediaFileManager, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public MediaService(ICoreScopeProvider provider, MediaFileManager mediaFileManager, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMediaRepository mediaRepository, IAuditRepository auditRepository, IMediaTypeRepository mediaTypeRepository, IEntityRepository entityRepository, IShortStringHelper shortStringHelper) : base(provider, loggerFactory, eventMessagesFactory) @@ -52,7 +52,7 @@ namespace Umbraco.Cms.Core.Services public int Count(string? mediaTypeAlias = null) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.Count(mediaTypeAlias); @@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Services public int CountNotTrashed(string? mediaTypeAlias = null) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); @@ -82,7 +82,7 @@ namespace Umbraco.Cms.Core.Services public int CountChildren(int parentId, string? mediaTypeAlias = null) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.CountChildren(parentId, mediaTypeAlias); @@ -91,7 +91,7 @@ namespace Umbraco.Cms.Core.Services public int CountDescendants(int parentId, string? mediaTypeAlias = null) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.CountDescendants(parentId, mediaTypeAlias); @@ -148,7 +148,7 @@ namespace Umbraco.Cms.Core.Services } var media = new Core.Models.Media(name, parentId, mediaType); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { CreateMedia(scope, media, parent!, userId, false); scope.Complete(); @@ -181,7 +181,7 @@ namespace Umbraco.Cms.Core.Services } var media = new Core.Models.Media(name, -1, mediaType); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { CreateMedia(scope, media, null, userId, false); scope.Complete(); @@ -206,7 +206,7 @@ namespace Umbraco.Cms.Core.Services { if (parent == null) throw new ArgumentNullException(nameof(parent)); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { // not locking since not saving anything @@ -237,7 +237,7 @@ namespace Umbraco.Cms.Core.Services /// The media object. public IMedia CreateMediaWithIdentity(string name, int parentId, string mediaTypeAlias, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { // locking the media tree secures media types too scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); @@ -271,7 +271,7 @@ namespace Umbraco.Cms.Core.Services { if (parent == null) throw new ArgumentNullException(nameof(parent)); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { // locking the media tree secures media types too scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); @@ -288,7 +288,7 @@ namespace Umbraco.Cms.Core.Services } } - private void CreateMedia(IScope scope, Core.Models.Media media, IMedia? parent, int userId, bool withIdentity) + private void CreateMedia(ICoreScope scope, Core.Models.Media media, IMedia? parent, int userId, bool withIdentity) { EventMessages eventMessages = EventMessagesFactory.Get(); @@ -325,7 +325,7 @@ namespace Umbraco.Cms.Core.Services /// public IMedia? GetById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.Get(id); @@ -342,7 +342,7 @@ namespace Umbraco.Cms.Core.Services var idsA = ids.ToArray(); if (idsA.Length == 0) return Enumerable.Empty(); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.GetMany(idsA); @@ -356,7 +356,7 @@ namespace Umbraco.Cms.Core.Services /// public IMedia? GetById(Guid key) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.Get(key); @@ -373,7 +373,7 @@ namespace Umbraco.Cms.Core.Services var idsA = ids.ToArray(); if (idsA.Length == 0) return Enumerable.Empty(); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.GetMany(idsA); @@ -389,7 +389,7 @@ namespace Umbraco.Cms.Core.Services if (ordering == null) ordering = Ordering.By("sortOrder"); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.ContentTree); return _mediaRepository.GetPage( @@ -407,7 +407,7 @@ namespace Umbraco.Cms.Core.Services if (ordering == null) ordering = Ordering.By("sortOrder"); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.ContentTree); return _mediaRepository.GetPage( @@ -424,7 +424,7 @@ namespace Umbraco.Cms.Core.Services /// Contrary to most methods, this method filters out trashed media items. public IEnumerable? GetByLevel(int level) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); var query = Query().Where(x => x.Level == level && x.Trashed == false); @@ -439,7 +439,7 @@ namespace Umbraco.Cms.Core.Services /// An item public IMedia? GetVersion(int versionId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.GetVersion(versionId); @@ -453,7 +453,7 @@ namespace Umbraco.Cms.Core.Services /// An Enumerable list of objects public IEnumerable GetVersions(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.GetAllVersions(id); @@ -490,7 +490,7 @@ namespace Umbraco.Cms.Core.Services if (ids.Any() == false) return new List(); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); return _mediaRepository.GetMany(ids); @@ -507,7 +507,7 @@ namespace Umbraco.Cms.Core.Services if (ordering == null) ordering = Ordering.By("sortOrder"); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); @@ -523,7 +523,7 @@ namespace Umbraco.Cms.Core.Services if (ordering == null) ordering = Ordering.By("Path"); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); @@ -592,7 +592,7 @@ namespace Umbraco.Cms.Core.Services /// An Enumerable list of objects public IEnumerable? GetRootMedia() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTree); var query = Query().Where(x => x.ParentId == Cms.Core.Constants.System.Root); @@ -604,7 +604,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetPagedMediaInRecycleBin(long pageIndex, int pageSize, out long totalRecords, IQuery? filter = null, Ordering? ordering = null) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { if (ordering == null) ordering = Ordering.By("Path"); @@ -622,7 +622,7 @@ namespace Umbraco.Cms.Core.Services /// True if the media has any children otherwise False public bool HasChildren(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == id); var count = _mediaRepository.Count(query); @@ -637,7 +637,7 @@ namespace Umbraco.Cms.Core.Services /// public IMedia? GetMediaByPath(string mediaPath) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _mediaRepository.GetMediaByPath(mediaPath); } @@ -658,7 +658,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages eventMessages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new MediaSavingNotification(media, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -706,7 +706,7 @@ namespace Umbraco.Cms.Core.Services EventMessages messages = EventMessagesFactory.Get(); IMedia[] mediasA = medias.ToArray(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new MediaSavingNotification(mediasA, messages); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -752,7 +752,7 @@ namespace Umbraco.Cms.Core.Services { EventMessages messages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { if (scope.Notifications.PublishCancelable(new MediaDeletingNotification(media, messages))) { @@ -773,7 +773,7 @@ namespace Umbraco.Cms.Core.Services return OperationResult.Attempt.Succeed(messages); } - private void DeleteLocked(IScope scope, IMedia media, EventMessages evtMsgs) + private void DeleteLocked(ICoreScope scope, IMedia media, EventMessages evtMsgs) { void DoDelete(IMedia c) { @@ -810,14 +810,14 @@ namespace Umbraco.Cms.Core.Services /// Optional Id of the User deleting versions of a Media object public void DeleteVersions(int id, DateTime versionDate, int userId = Cms.Core.Constants.Security.SuperUserId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { DeleteVersions(scope, true, id, versionDate, userId); scope.Complete(); } } - private void DeleteVersions(IScope scope, bool wlock, int id, DateTime versionDate, int userId = Cms.Core.Constants.Security.SuperUserId) + private void DeleteVersions(ICoreScope scope, bool wlock, int id, DateTime versionDate, int userId = Cms.Core.Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); @@ -847,7 +847,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var deletingVersionsNotification = new MediaDeletingVersionsNotification(id, evtMsgs, specificVersion: versionId); if (scope.Notifications.PublishCancelable(deletingVersionsNotification)) @@ -892,7 +892,7 @@ namespace Umbraco.Cms.Core.Services EventMessages messages = EventMessagesFactory.Get(); var moves = new List<(IMedia, string)>(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); @@ -942,7 +942,7 @@ namespace Umbraco.Cms.Core.Services var moves = new List<(IMedia, string)>(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); @@ -1043,7 +1043,7 @@ namespace Umbraco.Cms.Core.Services var deleted = new List(); EventMessages messages = EventMessagesFactory.Get(); // TODO: and then? - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); @@ -1074,7 +1074,7 @@ namespace Umbraco.Cms.Core.Services public bool RecycleBinSmells() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MediaTree); return _mediaRepository.RecycleBinSmells(); @@ -1102,7 +1102,7 @@ namespace Umbraco.Cms.Core.Services EventMessages messages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new MediaSavingNotification(itemsA, messages); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -1146,7 +1146,7 @@ namespace Umbraco.Cms.Core.Services public ContentDataIntegrityReport CheckDataIntegrity(ContentDataIntegrityReportOptions options) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); @@ -1234,7 +1234,7 @@ namespace Umbraco.Cms.Core.Services var mediaTypeIdsA = mediaTypeIds.ToArray(); EventMessages messages = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); @@ -1301,7 +1301,7 @@ namespace Umbraco.Cms.Core.Services if (mediaTypeAlias == null) throw new ArgumentNullException(nameof(mediaTypeAlias)); if (string.IsNullOrWhiteSpace(mediaTypeAlias)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(mediaTypeAlias)); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.ReadLock(Cms.Core.Constants.Locks.MediaTypes); diff --git a/src/Umbraco.Core/Services/MediaTypeService.cs b/src/Umbraco.Core/Services/MediaTypeService.cs index 49021333cc..6873fb4a39 100644 --- a/src/Umbraco.Core/Services/MediaTypeService.cs +++ b/src/Umbraco.Core/Services/MediaTypeService.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Services { public class MediaTypeService : ContentTypeServiceBase, IMediaTypeService { - public MediaTypeService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMediaService mediaService, + public MediaTypeService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMediaService mediaService, IMediaTypeRepository mediaTypeRepository, IAuditRepository auditRepository, IMediaTypeContainerRepository entityContainerRepository, IEntityRepository entityRepository, IEventAggregator eventAggregator) : base(provider, loggerFactory, eventMessagesFactory, mediaTypeRepository, auditRepository, entityContainerRepository, entityRepository, eventAggregator) diff --git a/src/Umbraco.Core/Services/MemberGroupService.cs b/src/Umbraco.Core/Services/MemberGroupService.cs index 305223979b..2290f9d84a 100644 --- a/src/Umbraco.Core/Services/MemberGroupService.cs +++ b/src/Umbraco.Core/Services/MemberGroupService.cs @@ -14,14 +14,14 @@ namespace Umbraco.Cms.Core.Services { private readonly IMemberGroupRepository _memberGroupRepository; - public MemberGroupService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public MemberGroupService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMemberGroupRepository memberGroupRepository) : base(provider, loggerFactory, eventMessagesFactory) => _memberGroupRepository = memberGroupRepository; public IEnumerable GetAll() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _memberGroupRepository.GetMany(); } @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Core.Services return new IMemberGroup[0]; } - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _memberGroupRepository.GetMany(ids.ToArray()); } @@ -42,7 +42,7 @@ namespace Umbraco.Cms.Core.Services public IMemberGroup? GetById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _memberGroupRepository.Get(id); } @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Core.Services public IMemberGroup? GetById(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _memberGroupRepository.Get(id); } @@ -58,7 +58,7 @@ namespace Umbraco.Cms.Core.Services public IMemberGroup? GetByName(string? name) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _memberGroupRepository.GetByName(name); } @@ -73,7 +73,7 @@ namespace Umbraco.Cms.Core.Services var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new MemberGroupSavingNotification(memberGroup, evtMsgs); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -93,7 +93,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var deletingNotification = new MemberGroupDeletingNotification(memberGroup, evtMsgs); if (scope.Notifications.PublishCancelable(deletingNotification)) diff --git a/src/Umbraco.Core/Services/MemberService.cs b/src/Umbraco.Core/Services/MemberService.cs index 95443c549d..402cc5405b 100644 --- a/src/Umbraco.Core/Services/MemberService.cs +++ b/src/Umbraco.Core/Services/MemberService.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Services #region Constructor - public MemberService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMemberGroupService memberGroupService, + public MemberService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMemberGroupService memberGroupService, IMemberRepository memberRepository, IMemberTypeRepository memberTypeRepository, IMemberGroupRepository memberGroupRepository, IAuditRepository auditRepository) : base(provider, loggerFactory, eventMessagesFactory) { @@ -55,7 +55,7 @@ namespace Umbraco.Cms.Core.Services /// with number of Members for passed in type public int GetCount(MemberCountType countType) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); @@ -88,7 +88,7 @@ namespace Umbraco.Cms.Core.Services /// with number of Members public int Count(string? memberTypeAlias = null) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.Count(memberTypeAlias); @@ -195,7 +195,7 @@ namespace Umbraco.Cms.Core.Services /// public IMember CreateMemberWithIdentity(string username, string email, string name, string passwordValue, string memberTypeAlias, bool isApproved = true) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { // locking the member tree secures member types too scope.WriteLock(Constants.Locks.MemberTree); @@ -262,7 +262,7 @@ namespace Umbraco.Cms.Core.Services { if (memberType == null) throw new ArgumentNullException(nameof(memberType)); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); @@ -296,7 +296,7 @@ namespace Umbraco.Cms.Core.Services /// public IMember? GetById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.Get(id); @@ -312,7 +312,7 @@ namespace Umbraco.Cms.Core.Services /// public IMember? GetByKey(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query = Query().Where(x => x.Key == id); @@ -329,7 +329,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAll(long pageIndex, int pageSize, out long totalRecords) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.GetPage(null, pageIndex, pageSize, out totalRecords, null, Ordering.By("LoginName")); @@ -345,7 +345,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAll(long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, bool orderBySystemField, string? memberTypeAlias, string filter) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query1 = memberTypeAlias == null ? null : Query()?.Where(x => x.ContentTypeAlias == memberTypeAlias); @@ -379,7 +379,7 @@ namespace Umbraco.Cms.Core.Services /// public IMember? GetByEmail(string email) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query = Query().Where(x => x.Email.Equals(email)); @@ -394,7 +394,7 @@ namespace Umbraco.Cms.Core.Services /// public IMember? GetByUsername(string? username) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.GetByUsername(username); @@ -408,7 +408,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetMembersByMemberType(string memberTypeAlias) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query = Query().Where(x => x.ContentTypeAlias == memberTypeAlias); @@ -423,7 +423,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetMembersByMemberType(int memberTypeId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query = Query().Where(x => x.ContentTypeId == memberTypeId); @@ -438,7 +438,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetMembersByGroup(string memberGroupName) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.GetByMemberGroup(memberGroupName); @@ -453,7 +453,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAllMembers(params int[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.GetMany(ids); @@ -471,7 +471,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable FindMembersByDisplayName(string displayNameToMatch, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query = Query(); @@ -512,7 +512,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable FindByEmail(string emailStringToMatch, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query = Query(); @@ -553,7 +553,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable FindByUsername(string login, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query = Query(); @@ -592,7 +592,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetMembersByPropertyValue(string propertyTypeAlias, string value, StringPropertyMatchType matchType = StringPropertyMatchType.Exact) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); IQuery query; @@ -628,7 +628,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetMembersByPropertyValue(string propertyTypeAlias, int value, ValuePropertyMatchType matchType = ValuePropertyMatchType.Exact) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); IQuery query; @@ -666,7 +666,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetMembersByPropertyValue(string propertyTypeAlias, bool value) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var query = Query().Where(x => ((Member) x).PropertyTypeAlias == propertyTypeAlias && ((Member) x).BoolPropertyValue == value); @@ -684,7 +684,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetMembersByPropertyValue(string propertyTypeAlias, DateTime value, ValuePropertyMatchType matchType = ValuePropertyMatchType.Exact) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); IQuery query; @@ -722,7 +722,7 @@ namespace Umbraco.Cms.Core.Services /// True if the Member exists otherwise False public bool Exists(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.Exists(id); @@ -736,7 +736,7 @@ namespace Umbraco.Cms.Core.Services /// True if the Member exists otherwise False public bool Exists(string username) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.Exists(username); @@ -762,7 +762,7 @@ namespace Umbraco.Cms.Core.Services var evtMsgs = EventMessagesFactory.Get(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new MemberSavingNotification(member, evtMsgs); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -795,7 +795,7 @@ namespace Umbraco.Cms.Core.Services var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new MemberSavingNotification(membersA, evtMsgs); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -835,7 +835,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var deletingNotification = new MemberDeletingNotification(member, evtMsgs); if (scope.Notifications.PublishCancelable(deletingNotification)) @@ -852,7 +852,7 @@ namespace Umbraco.Cms.Core.Services } } - private void DeleteLocked(IScope scope, IMember member, EventMessages evtMsgs, IDictionary? notificationState = null) + private void DeleteLocked(ICoreScope scope, IMember member, EventMessages evtMsgs, IDictionary? notificationState = null) { // a member has no descendants _memberRepository.Delete(member); @@ -867,7 +867,7 @@ namespace Umbraco.Cms.Core.Services public void AddRole(string roleName) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); _memberGroupRepository.CreateIfNotExists(roleName); @@ -882,7 +882,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAllRoles() { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberGroupRepository.GetMany().Distinct(); @@ -896,7 +896,7 @@ namespace Umbraco.Cms.Core.Services /// A list of member roles public IEnumerable? GetAllRoles(int memberId) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); var result = _memberGroupRepository.GetMemberGroupsForMember(memberId); @@ -906,7 +906,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAllRoles(string? username) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); IEnumerable result = _memberGroupRepository.GetMemberGroupsForMember(username); @@ -916,7 +916,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAllRolesIds() { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberGroupRepository.GetMany().Select(x => x.Id).Distinct(); @@ -925,7 +925,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAllRolesIds(int memberId) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); IEnumerable result = _memberGroupRepository.GetMemberGroupsForMember(memberId); @@ -935,7 +935,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAllRolesIds(string username) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); IEnumerable result = _memberGroupRepository.GetMemberGroupsForMember(username); @@ -945,7 +945,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetMembersInRole(string roleName) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.GetByMemberGroup(roleName); @@ -954,7 +954,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable FindMembersInRole(string roleName, string usernameToMatch, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Constants.Locks.MemberTree); return _memberRepository.FindMembersInRole(roleName, usernameToMatch, matchType); @@ -963,7 +963,7 @@ namespace Umbraco.Cms.Core.Services public bool DeleteRole(string roleName, bool throwIfBeingUsed) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); @@ -997,7 +997,7 @@ namespace Umbraco.Cms.Core.Services public void AssignRoles(string[] usernames, string[] roleNames) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); int[] ids = _memberRepository.GetMemberIds(usernames); @@ -1011,7 +1011,7 @@ namespace Umbraco.Cms.Core.Services public void DissociateRoles(string[] usernames, string[] roleNames) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); int[] ids = _memberRepository.GetMemberIds(usernames); @@ -1025,7 +1025,7 @@ namespace Umbraco.Cms.Core.Services public void AssignRoles(int[] memberIds, string[] roleNames) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); _memberGroupRepository.AssignRoles(memberIds, roleNames); @@ -1038,7 +1038,7 @@ namespace Umbraco.Cms.Core.Services public void DissociateRoles(int[] memberIds, string[] roleNames) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); _memberGroupRepository.DissociateRoles(memberIds, roleNames); @@ -1049,7 +1049,7 @@ namespace Umbraco.Cms.Core.Services public void ReplaceRoles(string[] usernames, string[] roleNames) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); int[] ids = _memberRepository.GetMemberIds(usernames); @@ -1061,7 +1061,7 @@ namespace Umbraco.Cms.Core.Services public void ReplaceRoles(int[] memberIds, string[] roleNames) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); _memberGroupRepository.ReplaceRoles(memberIds, roleNames); @@ -1090,7 +1090,7 @@ namespace Umbraco.Cms.Core.Services /// public MemberExportModel? ExportMember(Guid key) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { IQuery? query = Query().Where(x => x.Key == key); IMember? member = _memberRepository.Get(query)?.FirstOrDefault(); @@ -1159,7 +1159,7 @@ namespace Umbraco.Cms.Core.Services var evtMsgs = EventMessagesFactory.Get(); // note: no tree to manage here - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Constants.Locks.MemberTree); @@ -1190,7 +1190,7 @@ namespace Umbraco.Cms.Core.Services } } - private IMemberType GetMemberType(IScope scope, string memberTypeAlias) + private IMemberType GetMemberType(ICoreScope scope, string memberTypeAlias) { if (memberTypeAlias == null) { @@ -1226,7 +1226,7 @@ namespace Umbraco.Cms.Core.Services throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(memberTypeAlias)); } - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return GetMemberType(scope, memberTypeAlias); } diff --git a/src/Umbraco.Core/Services/MemberTypeService.cs b/src/Umbraco.Core/Services/MemberTypeService.cs index be3831c675..1157d42466 100644 --- a/src/Umbraco.Core/Services/MemberTypeService.cs +++ b/src/Umbraco.Core/Services/MemberTypeService.cs @@ -15,7 +15,7 @@ namespace Umbraco.Cms.Core.Services { private readonly IMemberTypeRepository _memberTypeRepository; - public MemberTypeService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMemberService memberService, + public MemberTypeService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMemberService memberService, IMemberTypeRepository memberTypeRepository, IAuditRepository auditRepository, IEntityRepository entityRepository, IEventAggregator eventAggregator) : base(provider, loggerFactory, eventMessagesFactory, memberTypeRepository, auditRepository, null, entityRepository, eventAggregator) { @@ -79,7 +79,7 @@ namespace Umbraco.Cms.Core.Services public string GetDefault() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(ReadLockIds); diff --git a/src/Umbraco.Core/Services/NodeCountService.cs b/src/Umbraco.Core/Services/NodeCountService.cs index 7fe77a22a5..7298d7f23a 100644 --- a/src/Umbraco.Core/Services/NodeCountService.cs +++ b/src/Umbraco.Core/Services/NodeCountService.cs @@ -8,9 +8,9 @@ namespace Umbraco.Cms.Infrastructure.Services.Implement public class NodeCountService : INodeCountService { private readonly INodeCountRepository _nodeCountRepository; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; - public NodeCountService(INodeCountRepository nodeCountRepository, IScopeProvider scopeProvider) + public NodeCountService(INodeCountRepository nodeCountRepository, ICoreScopeProvider scopeProvider) { _nodeCountRepository = nodeCountRepository; _scopeProvider = scopeProvider; @@ -18,13 +18,13 @@ namespace Umbraco.Cms.Infrastructure.Services.Implement public int GetNodeCount(Guid nodeType) { - using var scope = _scopeProvider.CreateScope(autoComplete: true); + using var scope = _scopeProvider.CreateCoreScope(autoComplete: true); return _nodeCountRepository.GetNodeCount(nodeType); } public int GetMediaCount() { - using var scope = _scopeProvider.CreateScope(autoComplete: true); + using var scope = _scopeProvider.CreateCoreScope(autoComplete: true); return _nodeCountRepository.GetMediaCount(); } } diff --git a/src/Umbraco.Core/Services/NotificationService.cs b/src/Umbraco.Core/Services/NotificationService.cs index b579f6f7f7..39aa6a863d 100644 --- a/src/Umbraco.Core/Services/NotificationService.cs +++ b/src/Umbraco.Core/Services/NotificationService.cs @@ -22,7 +22,7 @@ namespace Umbraco.Cms.Core.Services { public class NotificationService : INotificationService { - private readonly IScopeProvider _uowProvider; + private readonly ICoreScopeProvider _uowProvider; private readonly IUserService _userService; private readonly IContentService _contentService; private readonly ILocalizationService _localizationService; @@ -33,7 +33,7 @@ namespace Umbraco.Cms.Core.Services private readonly ILogger _logger; private readonly IIOHelper _ioHelper; - public NotificationService(IScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, + public NotificationService(ICoreScopeProvider provider, IUserService userService, IContentService contentService, ILocalizationService localizationService, ILogger logger, IIOHelper ioHelper, INotificationsRepository notificationsRepository, IOptions globalSettings, IOptions contentSettings, IEmailSender emailSender) { _notificationsRepository = notificationsRepository; @@ -140,7 +140,7 @@ namespace Umbraco.Cms.Core.Services private IEnumerable? GetUsersNotifications(IEnumerable userIds, string? action, IEnumerable nodeIds, Guid objectType) { - using (var scope = _uowProvider.CreateScope(autoComplete: true)) + using (var scope = _uowProvider.CreateCoreScope(autoComplete: true)) { return _notificationsRepository.GetUsersNotifications(userIds, action, nodeIds, objectType); } @@ -152,7 +152,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetUserNotifications(IUser user) { - using (var scope = _uowProvider.CreateScope(autoComplete: true)) + using (var scope = _uowProvider.CreateCoreScope(autoComplete: true)) { return _notificationsRepository.GetUserNotifications(user); } @@ -196,7 +196,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetEntityNotifications(IEntity entity) { - using (var scope = _uowProvider.CreateScope(autoComplete: true)) + using (var scope = _uowProvider.CreateCoreScope(autoComplete: true)) { return _notificationsRepository.GetEntityNotifications(entity); } @@ -208,7 +208,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteNotifications(IEntity entity) { - using (var scope = _uowProvider.CreateScope()) + using (var scope = _uowProvider.CreateCoreScope()) { _notificationsRepository.DeleteNotifications(entity); scope.Complete(); @@ -221,7 +221,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteNotifications(IUser user) { - using (var scope = _uowProvider.CreateScope()) + using (var scope = _uowProvider.CreateCoreScope()) { _notificationsRepository.DeleteNotifications(user); scope.Complete(); @@ -235,7 +235,7 @@ namespace Umbraco.Cms.Core.Services /// public void DeleteNotifications(IUser user, IEntity entity) { - using (var scope = _uowProvider.CreateScope()) + using (var scope = _uowProvider.CreateCoreScope()) { _notificationsRepository.DeleteNotifications(user, entity); scope.Complete(); @@ -258,7 +258,7 @@ namespace Umbraco.Cms.Core.Services return null; } - using (var scope = _uowProvider.CreateScope()) + using (var scope = _uowProvider.CreateCoreScope()) { var notifications = _notificationsRepository.SetNotifications(user, entity, actions); scope.Complete(); @@ -275,7 +275,7 @@ namespace Umbraco.Cms.Core.Services /// public Notification CreateNotification(IUser user, IEntity entity, string action) { - using (var scope = _uowProvider.CreateScope()) + using (var scope = _uowProvider.CreateCoreScope()) { var notification = _notificationsRepository.CreateNotification(user, entity, action); scope.Complete(); diff --git a/src/Umbraco.Core/Services/PublicAccessService.cs b/src/Umbraco.Core/Services/PublicAccessService.cs index 47431a97a3..b6216e4b58 100644 --- a/src/Umbraco.Core/Services/PublicAccessService.cs +++ b/src/Umbraco.Core/Services/PublicAccessService.cs @@ -16,7 +16,7 @@ namespace Umbraco.Cms.Core.Services { private readonly IPublicAccessRepository _publicAccessRepository; - public PublicAccessService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public PublicAccessService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IPublicAccessRepository publicAccessRepository) : base(provider, loggerFactory, eventMessagesFactory) { @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAll() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _publicAccessRepository.GetMany(); } @@ -65,7 +65,7 @@ namespace Umbraco.Cms.Core.Services //start with the deepest id ids.Reverse(); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { //This will retrieve from cache! var entries = _publicAccessRepository.GetMany().ToList(); @@ -112,7 +112,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); PublicAccessEntry? entry; - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { entry = _publicAccessRepository.GetMany().FirstOrDefault(x => x.ProtectedNodeId == content.Id); if (entry == null) @@ -156,7 +156,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); PublicAccessEntry? entry; - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { entry = _publicAccessRepository.GetMany().FirstOrDefault(x => x.ProtectedNodeId == content.Id); if (entry == null) return Attempt.Fail(); // causes rollback // causes rollback @@ -190,7 +190,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var savingNotifiation = new PublicAccessEntrySavingNotification(entry, evtMsgs); if (scope.Notifications.PublishCancelable(savingNotifiation)) @@ -216,7 +216,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var deletingNotification = new PublicAccessEntryDeletingNotification(entry, evtMsgs); if (scope.Notifications.PublishCancelable(deletingNotification)) diff --git a/src/Umbraco.Core/Services/RedirectUrlService.cs b/src/Umbraco.Core/Services/RedirectUrlService.cs index 545b994557..14c3e834bf 100644 --- a/src/Umbraco.Core/Services/RedirectUrlService.cs +++ b/src/Umbraco.Core/Services/RedirectUrlService.cs @@ -12,7 +12,7 @@ namespace Umbraco.Cms.Core.Services { private readonly IRedirectUrlRepository _redirectUrlRepository; - public RedirectUrlService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public RedirectUrlService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IRedirectUrlRepository redirectUrlRepository) : base(provider, loggerFactory, eventMessagesFactory) { @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Core.Services public void Register(string url, Guid contentKey, string? culture = null) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var redir = _redirectUrlRepository.Get(url, contentKey, culture); if (redir != null) @@ -35,7 +35,7 @@ namespace Umbraco.Cms.Core.Services public void Delete(IRedirectUrl redirectUrl) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _redirectUrlRepository.Delete(redirectUrl); scope.Complete(); @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Core.Services public void Delete(Guid id) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _redirectUrlRepository.Delete(id); scope.Complete(); @@ -53,7 +53,7 @@ namespace Umbraco.Cms.Core.Services public void DeleteContentRedirectUrls(Guid contentKey) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _redirectUrlRepository.DeleteContentUrls(contentKey); scope.Complete(); @@ -62,7 +62,7 @@ namespace Umbraco.Cms.Core.Services public void DeleteAll() { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _redirectUrlRepository.DeleteAll(); scope.Complete(); @@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.Services public IRedirectUrl? GetMostRecentRedirectUrl(string url) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _redirectUrlRepository.GetMostRecentUrl(url); } @@ -79,7 +79,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetContentRedirectUrls(Guid contentKey) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _redirectUrlRepository.GetContentUrls(contentKey); } @@ -87,7 +87,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAllRedirectUrls(long pageIndex, int pageSize, out long total) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _redirectUrlRepository.GetAllUrls(pageIndex, pageSize, out total); } @@ -95,7 +95,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAllRedirectUrls(int rootContentId, long pageIndex, int pageSize, out long total) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _redirectUrlRepository.GetAllUrls(rootContentId, pageIndex, pageSize, out total); } @@ -103,7 +103,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable SearchRedirectUrls(string searchTerm, long pageIndex, int pageSize, out long total) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _redirectUrlRepository.SearchUrls(searchTerm, pageIndex, pageSize, out total); } @@ -112,7 +112,7 @@ namespace Umbraco.Cms.Core.Services public IRedirectUrl? GetMostRecentRedirectUrl(string url, string? culture) { if (string.IsNullOrWhiteSpace(culture)) return GetMostRecentRedirectUrl(url); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _redirectUrlRepository.GetMostRecentUrl(url, culture); } diff --git a/src/Umbraco.Core/Services/RelationService.cs b/src/Umbraco.Core/Services/RelationService.cs index 667622c5c1..90762c3c74 100644 --- a/src/Umbraco.Core/Services/RelationService.cs +++ b/src/Umbraco.Core/Services/RelationService.cs @@ -20,7 +20,7 @@ namespace Umbraco.Cms.Core.Services private readonly IRelationTypeRepository _relationTypeRepository; private readonly IAuditRepository _auditRepository; - public RelationService(IScopeProvider uowProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IEntityService entityService, + public RelationService(ICoreScopeProvider uowProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IEntityService entityService, IRelationRepository relationRepository, IRelationTypeRepository relationTypeRepository, IAuditRepository auditRepository) : base(uowProvider, loggerFactory, eventMessagesFactory) { @@ -33,7 +33,7 @@ namespace Umbraco.Cms.Core.Services /// public IRelation? GetById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _relationRepository.Get(id); } @@ -42,7 +42,7 @@ namespace Umbraco.Cms.Core.Services /// public IRelationType? GetRelationTypeById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _relationTypeRepository.Get(id); } @@ -51,7 +51,7 @@ namespace Umbraco.Cms.Core.Services /// public IRelationType? GetRelationTypeById(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _relationTypeRepository.Get(id); } @@ -63,7 +63,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAllRelations(params int[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _relationRepository.GetMany(ids); } @@ -78,7 +78,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetAllRelationsByRelationType(int relationTypeId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.RelationTypeId == relationTypeId); return _relationRepository.Get(query); @@ -88,7 +88,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAllRelationTypes(params int[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _relationTypeRepository.GetMany(ids); } @@ -100,7 +100,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetByParentId(int id, string? relationTypeAlias) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { if (relationTypeAlias.IsNullOrWhiteSpace()) { @@ -129,7 +129,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetByChildId(int id, string? relationTypeAlias) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { if (relationTypeAlias.IsNullOrWhiteSpace()) { @@ -155,7 +155,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetByParentOrChildId(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ChildId == id || x.ParentId == id); return _relationRepository.Get(query); @@ -164,7 +164,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable? GetByParentOrChildId(int id, string relationTypeAlias) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var relationType = GetRelationType(relationTypeAlias); if (relationType == null) @@ -178,7 +178,7 @@ namespace Umbraco.Cms.Core.Services /// public IRelation? GetByParentAndChildId(int parentId, int childId, IRelationType relationType) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == parentId && x.ChildId == childId && @@ -191,7 +191,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetByRelationTypeName(string relationTypeName) { List? relationTypeIds; - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { //This is a silly query - but i guess it's needed in case someone has more than one relation with the same Name (not alias), odd. var query = Query().Where(x => x.Name == relationTypeName); @@ -217,7 +217,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable? GetByRelationTypeId(int relationTypeId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.RelationTypeId == relationTypeId); return _relationRepository.Get(query); @@ -227,7 +227,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetPagedByRelationTypeId(int relationTypeId, long pageIndex, int pageSize, out long totalRecords, Ordering? ordering = null) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query()?.Where(x => x.RelationTypeId == relationTypeId); return _relationRepository.GetPagedRelationsByQuery(query, pageIndex, pageSize, out totalRecords, ordering); @@ -298,7 +298,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetPagedParentEntitiesByChildId(int id, long pageIndex, int pageSize, out long totalChildren, params UmbracoObjectTypes[] entityTypes) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _relationRepository.GetPagedParentEntitiesByChildId(id, pageIndex, pageSize, out totalChildren, entityTypes.Select(x => x.GetGuid()).ToArray()); } @@ -307,7 +307,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetPagedChildEntitiesByParentId(int id, long pageIndex, int pageSize, out long totalChildren, params UmbracoObjectTypes[] entityTypes) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _relationRepository.GetPagedChildEntitiesByParentId(id, pageIndex, pageSize, out totalChildren, entityTypes.Select(x => x.GetGuid()).ToArray()); } @@ -346,7 +346,7 @@ namespace Umbraco.Cms.Core.Services var relation = new Relation(parentId, childId, relationType); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new RelationSavingNotification(relation, eventMessages); @@ -392,7 +392,7 @@ namespace Umbraco.Cms.Core.Services /// public bool HasRelations(IRelationType relationType) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.RelationTypeId == relationType.Id); return _relationRepository.Get(query)?.Any() ?? false; @@ -402,7 +402,7 @@ namespace Umbraco.Cms.Core.Services /// public bool IsRelated(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == id || x.ChildId == id); return _relationRepository.Get(query)?.Any() ?? false; @@ -412,7 +412,7 @@ namespace Umbraco.Cms.Core.Services /// public bool AreRelated(int parentId, int childId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == parentId && x.ChildId == childId); return _relationRepository.Get(query)?.Any() ?? false; @@ -433,7 +433,7 @@ namespace Umbraco.Cms.Core.Services /// public bool AreRelated(int parentId, int childId, IRelationType relationType) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.ParentId == parentId && x.ChildId == childId && x.RelationTypeId == relationType.Id); return _relationRepository.Get(query)?.Any() ?? false; @@ -456,7 +456,7 @@ namespace Umbraco.Cms.Core.Services /// public void Save(IRelation relation) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new RelationSavingNotification(relation, eventMessages); @@ -474,7 +474,7 @@ namespace Umbraco.Cms.Core.Services public void Save(IEnumerable relations) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { IRelation[] relationsA = relations.ToArray(); @@ -495,7 +495,7 @@ namespace Umbraco.Cms.Core.Services /// public void Save(IRelationType relationType) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new RelationTypeSavingNotification(relationType, eventMessages); @@ -515,7 +515,7 @@ namespace Umbraco.Cms.Core.Services /// public void Delete(IRelation relation) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var deletingNotification = new RelationDeletingNotification(relation, eventMessages); @@ -534,7 +534,7 @@ namespace Umbraco.Cms.Core.Services /// public void Delete(IRelationType relationType) { - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var deletingNotification = new RelationTypeDeletingNotification(relationType, eventMessages); @@ -554,7 +554,7 @@ namespace Umbraco.Cms.Core.Services public void DeleteRelationsOfType(IRelationType relationType) { var relations = new List(); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { IQuery? query = Query().Where(x => x.RelationTypeId == relationType.Id); var allRelations = _relationRepository.Get(query)?.ToList(); @@ -580,7 +580,7 @@ namespace Umbraco.Cms.Core.Services private IRelationType? GetRelationType(string relationTypeAlias) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.Alias == relationTypeAlias); return _relationTypeRepository.Get(query)?.FirstOrDefault(); @@ -590,7 +590,7 @@ namespace Umbraco.Cms.Core.Services private IEnumerable GetRelationsByListOfTypeIds(IEnumerable relationTypeIds) { var relations = new List(); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { foreach (var relationTypeId in relationTypeIds) { diff --git a/src/Umbraco.Core/Services/RepositoryService.cs b/src/Umbraco.Core/Services/RepositoryService.cs index 825c30e43d..85e78672ee 100644 --- a/src/Umbraco.Core/Services/RepositoryService.cs +++ b/src/Umbraco.Core/Services/RepositoryService.cs @@ -13,11 +13,11 @@ namespace Umbraco.Cms.Core.Services { protected IEventMessagesFactory EventMessagesFactory { get; } - protected IScopeProvider ScopeProvider { get; } + protected ICoreScopeProvider ScopeProvider { get; } protected ILoggerFactory LoggerFactory { get; } - protected RepositoryService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory) + protected RepositoryService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory) { EventMessagesFactory = eventMessagesFactory ?? throw new ArgumentNullException(nameof(eventMessagesFactory)); ScopeProvider = provider ?? throw new ArgumentNullException(nameof(provider)); diff --git a/src/Umbraco.Core/Services/TagService.cs b/src/Umbraco.Core/Services/TagService.cs index 576339ddd4..65e4a32f9e 100644 --- a/src/Umbraco.Core/Services/TagService.cs +++ b/src/Umbraco.Core/Services/TagService.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Services { private readonly ITagRepository _tagRepository; - public TagService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public TagService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, ITagRepository tagRepository) : base(provider, loggerFactory, eventMessagesFactory) { @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Services /// public TaggedEntity? GetTaggedEntityById(int id) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTaggedEntityById(id); } @@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.Services /// public TaggedEntity? GetTaggedEntityByKey(Guid key) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTaggedEntityByKey(key); } @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTaggedContentByTagGroup(string group, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Content, group, culture); } @@ -55,7 +55,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTaggedContentByTag(string tag, string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTaggedEntitiesByTag(TaggableObjectTypes.Content, tag, group, culture); } @@ -64,7 +64,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTaggedMediaByTagGroup(string group, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Media, group, culture); } @@ -73,7 +73,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTaggedMediaByTag(string tag, string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTaggedEntitiesByTag(TaggableObjectTypes.Media, tag, group, culture); } @@ -82,7 +82,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTaggedMembersByTagGroup(string group, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTaggedEntitiesByTagGroup(TaggableObjectTypes.Member, group, culture); } @@ -91,7 +91,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTaggedMembersByTag(string tag, string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTaggedEntitiesByTag(TaggableObjectTypes.Member, tag, group, culture); } @@ -100,7 +100,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAllTags(string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTagsForEntityType(TaggableObjectTypes.All, group, culture); } @@ -109,7 +109,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAllContentTags(string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTagsForEntityType(TaggableObjectTypes.Content, group, culture); } @@ -118,7 +118,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAllMediaTags(string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTagsForEntityType(TaggableObjectTypes.Media, group, culture); } @@ -127,7 +127,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAllMemberTags(string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTagsForEntityType(TaggableObjectTypes.Member, group, culture); } @@ -136,7 +136,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTagsForProperty(int contentId, string propertyTypeAlias, string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTagsForProperty(contentId, propertyTypeAlias, group, culture); } @@ -145,7 +145,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTagsForEntity(int contentId, string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTagsForEntity(contentId, group, culture); } @@ -154,7 +154,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTagsForProperty(Guid contentId, string propertyTypeAlias, string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTagsForProperty(contentId, propertyTypeAlias, group, culture); } @@ -163,7 +163,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetTagsForEntity(Guid contentId, string? group = null, string? culture = null) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _tagRepository.GetTagsForEntity(contentId, group, culture); } diff --git a/src/Umbraco.Core/Services/TrackedReferencesService.cs b/src/Umbraco.Core/Services/TrackedReferencesService.cs index cce3e0fc74..ab5a09ce8b 100644 --- a/src/Umbraco.Core/Services/TrackedReferencesService.cs +++ b/src/Umbraco.Core/Services/TrackedReferencesService.cs @@ -7,10 +7,10 @@ namespace Umbraco.Cms.Core.Services public class TrackedReferencesService : ITrackedReferencesService { private readonly ITrackedReferencesRepository _trackedReferencesRepository; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IEntityService _entityService; - public TrackedReferencesService(ITrackedReferencesRepository trackedReferencesRepository, IScopeProvider scopeProvider, IEntityService entityService) + public TrackedReferencesService(ITrackedReferencesRepository trackedReferencesRepository, ICoreScopeProvider scopeProvider, IEntityService entityService) { _trackedReferencesRepository = trackedReferencesRepository; _scopeProvider = scopeProvider; @@ -23,7 +23,7 @@ namespace Umbraco.Cms.Core.Services /// public PagedResult GetPagedRelationsForItem(int id, long pageIndex, int pageSize, bool filterMustBeIsDependency) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); var items = _trackedReferencesRepository.GetPagedRelationsForItem(id, pageIndex, pageSize, filterMustBeIsDependency, out var totalItems); return new PagedResult(totalItems, pageIndex + 1, pageSize) { Items = items }; @@ -34,7 +34,7 @@ namespace Umbraco.Cms.Core.Services /// public PagedResult GetPagedItemsWithRelations(int[] ids, long pageIndex, int pageSize, bool filterMustBeIsDependency) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); var items = _trackedReferencesRepository.GetPagedItemsWithRelations(ids, pageIndex, pageSize, filterMustBeIsDependency, out var totalItems); return new PagedResult(totalItems, pageIndex + 1, pageSize) { Items = items }; @@ -45,7 +45,7 @@ namespace Umbraco.Cms.Core.Services /// public PagedResult GetPagedDescendantsInReferences(int parentId, long pageIndex, int pageSize, bool filterMustBeIsDependency) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); var items = _trackedReferencesRepository.GetPagedDescendantsInReferences( parentId, diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index e280fa98e8..6179f5560e 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.Services private readonly GlobalSettings _globalSettings; private readonly ILogger _logger; - public UserService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IRuntimeState runtimeState, + public UserService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IRuntimeState runtimeState, IUserRepository userRepository, IUserGroupRepository userGroupRepository, IOptions globalSettings) : base(provider, loggerFactory, eventMessagesFactory) { @@ -51,7 +51,7 @@ namespace Umbraco.Cms.Core.Services /// True if the User exists otherwise False public bool Exists(string username) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.ExistsByUserName(username); } @@ -116,7 +116,7 @@ namespace Umbraco.Cms.Core.Services // TODO: PUT lock here!! User user; - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var loginExists = _userRepository.ExistsByLogin(username); if (loginExists) @@ -156,7 +156,7 @@ namespace Umbraco.Cms.Core.Services /// public IUser? GetById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.Get(id); } @@ -180,7 +180,7 @@ namespace Umbraco.Cms.Core.Services /// public IUser? GetByEmail(string email) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.Email.Equals(email)); return _userRepository.Get(query)?.FirstOrDefault(); @@ -199,7 +199,7 @@ namespace Umbraco.Cms.Core.Services return null; } - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { try { @@ -249,7 +249,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var deletingNotification = new UserDeletingNotification(user, evtMsgs); if (scope.Notifications.PublishCancelable(deletingNotification)) @@ -281,7 +281,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new UserSavingNotification(entity, evtMsgs); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -326,7 +326,7 @@ namespace Umbraco.Cms.Core.Services var entitiesA = entities.ToArray(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var savingNotification = new UserSavingNotification(entitiesA, evtMsgs); if (scope.Notifications.PublishCancelable(savingNotification)) @@ -374,7 +374,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable FindByEmail(string emailStringToMatch, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query(); @@ -414,7 +414,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable FindByUsername(string login, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query(); @@ -455,7 +455,7 @@ namespace Umbraco.Cms.Core.Services /// with number of Users for passed in type public int GetCount(MemberCountType countType) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { IQuery? query; @@ -480,7 +480,7 @@ namespace Umbraco.Cms.Core.Services public Guid CreateLoginSession(int userId, string requestingIpAddress) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var session = _userRepository.CreateLoginSession(userId, requestingIpAddress); scope.Complete(); @@ -490,7 +490,7 @@ namespace Umbraco.Cms.Core.Services public int ClearLoginSessions(int userId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var count = _userRepository.ClearLoginSessions(userId); scope.Complete(); @@ -500,7 +500,7 @@ namespace Umbraco.Cms.Core.Services public void ClearLoginSession(Guid sessionId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _userRepository.ClearLoginSession(sessionId); scope.Complete(); @@ -509,14 +509,14 @@ namespace Umbraco.Cms.Core.Services public bool ValidateLoginSession(int userId, Guid sessionId) { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.ValidateLoginSession(userId, sessionId); } } public IDictionary GetUserStates() { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.GetUserStates(); } @@ -535,7 +535,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetAll(long pageIndex, int pageSize, out long totalRecords, string orderBy, Direction orderDirection, UserState[]? userState = null, string[]? includeUserGroups = null, string[]? excludeUserGroups = null, IQuery? filter = null) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { Expression> sort; switch (orderBy.ToUpperInvariant()) @@ -587,7 +587,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAll(long pageIndex, int pageSize, out long totalRecords) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.GetPagedResultsByQuery(null, pageIndex, pageSize, out totalRecords, member => member.Name); } @@ -595,7 +595,7 @@ namespace Umbraco.Cms.Core.Services public IEnumerable GetNextUsers(int id, int count) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.GetNextUsers(id, count); } @@ -612,7 +612,8 @@ namespace Umbraco.Cms.Core.Services { return Array.Empty(); } - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.GetAllInGroup(groupId.Value); } @@ -625,7 +626,7 @@ namespace Umbraco.Cms.Core.Services /// public IEnumerable GetAllNotInGroup(int groupId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { return _userRepository.GetAllNotInGroup(groupId); } @@ -656,7 +657,7 @@ namespace Umbraco.Cms.Core.Services /// public IProfile? GetProfileByUserName(string username) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.GetProfile(username); } @@ -669,7 +670,7 @@ namespace Umbraco.Cms.Core.Services /// public IUser? GetUserById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { try { @@ -696,7 +697,7 @@ namespace Umbraco.Cms.Core.Services { if (ids?.Length <= 0) return Enumerable.Empty(); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userRepository.GetMany(ids); } @@ -716,7 +717,7 @@ namespace Umbraco.Cms.Core.Services var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _userGroupRepository.ReplaceGroupPermissions(groupId, permissions, entityIds); scope.Complete(); @@ -743,7 +744,7 @@ namespace Umbraco.Cms.Core.Services var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _userGroupRepository.AssignGroupPermission(groupId, permission, entityIds); scope.Complete(); @@ -761,7 +762,7 @@ namespace Umbraco.Cms.Core.Services /// An enumerable list of public IEnumerable GetAllUserGroups(params int[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userGroupRepository.GetMany(ids).OrderBy(x => x.Name); } @@ -771,7 +772,7 @@ namespace Umbraco.Cms.Core.Services { if (aliases.Length == 0) return Enumerable.Empty(); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => aliases.SqlIn(x.Alias)); var contents = _userGroupRepository.Get(query); @@ -788,7 +789,7 @@ namespace Umbraco.Cms.Core.Services { if (string.IsNullOrWhiteSpace(alias)) throw new ArgumentException("Value cannot be null or whitespace.", "alias"); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.Alias == alias); var contents = _userGroupRepository.Get(query); @@ -803,7 +804,7 @@ namespace Umbraco.Cms.Core.Services /// public IUserGroup? GetUserGroupById(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userGroupRepository.Get(id); } @@ -822,7 +823,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { // we need to figure out which users have been added / removed, for audit purposes var empty = new IUser[0]; @@ -875,7 +876,7 @@ namespace Umbraco.Cms.Core.Services { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var deletingNotification = new UserGroupDeletingNotification(userGroup, evtMsgs); if (scope.Notifications.PublishCancelable(deletingNotification)) @@ -899,7 +900,7 @@ namespace Umbraco.Cms.Core.Services /// Alias of the section to remove public void DeleteSectionFromAllUserGroups(string sectionAlias) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var assignedGroups = _userGroupRepository.GetGroupsAssignedToSection(sectionAlias); foreach (var group in assignedGroups) @@ -922,7 +923,7 @@ namespace Umbraco.Cms.Core.Services /// An enumerable list of public EntityPermissionCollection GetPermissions(IUser? user, params int[] nodeIds) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userGroupRepository.GetPermissions(user?.Groups.ToArray(), true, nodeIds); } @@ -941,7 +942,7 @@ namespace Umbraco.Cms.Core.Services { if (groups == null) throw new ArgumentNullException(nameof(groups)); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userGroupRepository.GetPermissions(groups, fallbackToDefaultPermissions, nodeIds); } @@ -959,7 +960,7 @@ namespace Umbraco.Cms.Core.Services public EntityPermissionCollection GetPermissions(IUserGroup?[] groups, bool fallbackToDefaultPermissions, params int[] nodeIds) { if (groups == null) throw new ArgumentNullException(nameof(groups)); - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _userGroupRepository.GetPermissions(groups.WhereNotNull().Select(x => x.ToReadOnlyGroup()).ToArray(), fallbackToDefaultPermissions, nodeIds); } diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index af212673a0..2a429fc6c5 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -98,7 +98,9 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection // register the scope provider builder.Services.AddSingleton(); // implements IScopeProvider, IScopeAccessor - builder.Services.AddSingleton(f => f.GetRequiredService()); + builder.Services.AddSingleton(f => f.GetRequiredService()); + builder.Services.AddSingleton(f => f.GetRequiredService()); + builder.Services.AddSingleton(f => f.GetRequiredService()); builder.Services.AddSingleton(f => f.GetRequiredService()); diff --git a/src/Umbraco.Infrastructure/DistributedLocking/DefaultDistributedLockingMechanismFactory.cs b/src/Umbraco.Infrastructure/DistributedLocking/DefaultDistributedLockingMechanismFactory.cs index 2f48a438c0..7916de3996 100644 --- a/src/Umbraco.Infrastructure/DistributedLocking/DefaultDistributedLockingMechanismFactory.cs +++ b/src/Umbraco.Infrastructure/DistributedLocking/DefaultDistributedLockingMechanismFactory.cs @@ -12,7 +12,7 @@ public class DefaultDistributedLockingMechanismFactory : IDistributedLockingMech { private object _lock = new(); private bool _initialized; - private IDistributedLockingMechanism? _distributedLockingMechanism; + private IDistributedLockingMechanism _distributedLockingMechanism = null!; private readonly IOptionsMonitor _globalSettings; private readonly IEnumerable _distributedLockingMechanisms; @@ -25,7 +25,7 @@ public class DefaultDistributedLockingMechanismFactory : IDistributedLockingMech _distributedLockingMechanisms = distributedLockingMechanisms; } - public IDistributedLockingMechanism? DistributedLockingMechanism + public IDistributedLockingMechanism DistributedLockingMechanism { get { diff --git a/src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs b/src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs index 0be7a18fef..c8a07f6193 100644 --- a/src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs +++ b/src/Umbraco.Infrastructure/Examine/ExamineUmbracoIndexingHandler.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Infrastructure.Examine private readonly IMainDom _mainDom; private readonly ILogger _logger; private readonly IProfilingLogger _profilingLogger; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IExamineManager _examineManager; private readonly IBackgroundTaskQueue _backgroundTaskQueue; private readonly IContentValueSetBuilder _contentValueSetBuilder; @@ -41,7 +41,7 @@ namespace Umbraco.Cms.Infrastructure.Examine IMainDom mainDom, ILogger logger, IProfilingLogger profilingLogger, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IExamineManager examineManager, IBackgroundTaskQueue backgroundTaskQueue, IContentValueSetBuilder contentValueSetBuilder, @@ -214,7 +214,7 @@ namespace Umbraco.Cms.Infrastructure.Examine { private readonly List _actions = new List(); - public static DeferedActions? Get(IScopeProvider scopeProvider) + public static DeferedActions? Get(ICoreScopeProvider scopeProvider) { IScopeContext? scopeContext = scopeProvider.Context; @@ -272,7 +272,7 @@ namespace Umbraco.Cms.Infrastructure.Examine public static void Execute(IBackgroundTaskQueue backgroundTaskQueue, ExamineUmbracoIndexingHandler examineUmbracoIndexingHandler, IContent content, bool isPublished) => backgroundTaskQueue.QueueBackgroundWorkItem(cancellationToken => { - using IScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateCoreScope(autoComplete: true); // for content we have a different builder for published vs unpublished // we don't want to build more value sets than is needed so we'll lazily build 2 one for published one for non-published @@ -325,7 +325,7 @@ namespace Umbraco.Cms.Infrastructure.Examine // perform the ValueSet lookup on a background thread backgroundTaskQueue.QueueBackgroundWorkItem(cancellationToken => { - using IScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateCoreScope(autoComplete: true); var valueSet = examineUmbracoIndexingHandler._mediaValueSetBuilder.GetValueSets(media).ToList(); @@ -364,7 +364,7 @@ namespace Umbraco.Cms.Infrastructure.Examine // perform the ValueSet lookup on a background thread backgroundTaskQueue.QueueBackgroundWorkItem(cancellationToken => { - using IScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = examineUmbracoIndexingHandler._scopeProvider.CreateCoreScope(autoComplete: true); var valueSet = examineUmbracoIndexingHandler._memberValueSetBuilder.GetValueSets(member).ToList(); diff --git a/src/Umbraco.Infrastructure/HostedServices/HealthCheckNotifier.cs b/src/Umbraco.Infrastructure/HostedServices/HealthCheckNotifier.cs index 33a069e9ac..efbb30291e 100644 --- a/src/Umbraco.Infrastructure/HostedServices/HealthCheckNotifier.cs +++ b/src/Umbraco.Infrastructure/HostedServices/HealthCheckNotifier.cs @@ -32,7 +32,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices private readonly IRuntimeState _runtimeState; private readonly IServerRoleAccessor _serverRegistrar; private readonly IMainDom _mainDom; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly ILogger _logger; private readonly IProfilingLogger _profilingLogger; @@ -56,7 +56,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices IRuntimeState runtimeState, IServerRoleAccessor serverRegistrar, IMainDom mainDom, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, ILogger logger, IProfilingLogger profilingLogger, ICronTabParser cronTabParser) @@ -114,7 +114,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices // Ensure we use an explicit scope since we are running on a background thread and plugin health // checks can be making service/database calls so we want to ensure the CallContext/Ambient scope // isn't used since that can be problematic. - using (IScope scope = _scopeProvider.CreateScope()) + using (ICoreScope scope = _scopeProvider.CreateCoreScope()) using (_profilingLogger.DebugDuration("Health checks executing", "Health checks complete")) { // Don't notify for any checks that are disabled, nor for any disabled just for notifications. diff --git a/src/Umbraco.Infrastructure/HostedServices/LogScrubber.cs b/src/Umbraco.Infrastructure/HostedServices/LogScrubber.cs index 6c59b21fd9..4877c4cb25 100644 --- a/src/Umbraco.Infrastructure/HostedServices/LogScrubber.cs +++ b/src/Umbraco.Infrastructure/HostedServices/LogScrubber.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices private LoggingSettings _settings; private readonly IProfilingLogger _profilingLogger; private readonly ILogger _logger; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; /// /// Initializes a new instance of the class. @@ -45,7 +45,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices IServerRoleAccessor serverRegistrar, IAuditService auditService, IOptionsMonitor settings, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, ILogger logger, IProfilingLogger profilingLogger) : base(logger, TimeSpan.FromHours(4), DefaultDelay) @@ -80,7 +80,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices } // Ensure we use an explicit scope since we are running on a background thread. - using (IScope scope = _scopeProvider.CreateScope()) + using (ICoreScope scope = _scopeProvider.CreateCoreScope()) using (_profilingLogger.DebugDuration("Log scrubbing executing", "Log scrubbing complete")) { _auditService.CleanLogs((int)_settings.MaxLogAge.TotalMinutes); diff --git a/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs b/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs index 4a70e69c71..6d659425e0 100644 --- a/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs +++ b/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices private readonly IMainDom _mainDom; private readonly IRuntimeState _runtimeState; private readonly IServerMessenger _serverMessenger; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IServerRoleAccessor _serverRegistrar; private readonly IUmbracoContextFactory _umbracoContextFactory; @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices IUmbracoContextFactory umbracoContextFactory, ILogger logger, IServerMessenger serverMessenger, - IScopeProvider scopeProvider) + ICoreScopeProvider scopeProvider) : base(logger, TimeSpan.FromMinutes(1), DefaultDelay) { _runtimeState = runtimeState; @@ -100,7 +100,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices // - and we should definitively *not* have to flush it here (should be auto) using UmbracoContextReference contextReference = _umbracoContextFactory.EnsureUmbracoContext(); - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); /* We used to assume that there will never be two instances running concurrently where (IsMainDom && ServerRole == SchedulingPublisher) * However this is possible during an azure deployment slot swap for the SchedulingPublisher instance when trying to achieve zero downtime deployments. diff --git a/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs b/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs index 2af5266247..100e3ee26f 100644 --- a/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs +++ b/src/Umbraco.Infrastructure/Install/PackageMigrationRunner.cs @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Infrastructure.Install public class PackageMigrationRunner { private readonly IProfilingLogger _profilingLogger; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly PendingPackageMigrations _pendingPackageMigrations; private readonly IMigrationPlanExecutor _migrationPlanExecutor; private readonly IKeyValueService _keyValueService; @@ -30,7 +30,7 @@ namespace Umbraco.Cms.Infrastructure.Install public PackageMigrationRunner( IProfilingLogger profilingLogger, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, PendingPackageMigrations pendingPackageMigrations, PackageMigrationPlanCollection packageMigrationPlans, IMigrationPlanExecutor migrationPlanExecutor, @@ -79,7 +79,7 @@ namespace Umbraco.Cms.Infrastructure.Install // all executed in a single transaction. If one package migration fails, // none of them will be committed. This is intended behavior so we can // ensure when we publish the success notification that is is done when they all succeed. - using (IScope scope = _scopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { foreach (var migrationName in plansToRun) { diff --git a/src/Umbraco.Infrastructure/Mapping/UmbracoMapper.cs b/src/Umbraco.Infrastructure/Mapping/UmbracoMapper.cs index 7810e8468a..d7d0438702 100644 --- a/src/Umbraco.Infrastructure/Mapping/UmbracoMapper.cs +++ b/src/Umbraco.Infrastructure/Mapping/UmbracoMapper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; @@ -44,14 +44,14 @@ namespace Umbraco.Cms.Core.Mapping private readonly ConcurrentDictionary>> _maps = new ConcurrentDictionary>>(); - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; /// /// Initializes a new instance of the class. /// /// /// - public UmbracoMapper(MapDefinitionCollection profiles, IScopeProvider scopeProvider) + public UmbracoMapper(MapDefinitionCollection profiles, ICoreScopeProvider scopeProvider) { _scopeProvider = scopeProvider; @@ -210,7 +210,7 @@ namespace Umbraco.Cms.Core.Mapping if (ctor != null && map != null) { var target = ctor(source, context); - using (var scope = _scopeProvider.CreateScope(autoComplete: true)) + using (var scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { map(source, target, context); } @@ -259,7 +259,7 @@ namespace Umbraco.Cms.Core.Mapping { var targetList = (IList?)Activator.CreateInstance(typeof(List<>).MakeGenericType(targetGenericArg)); - using (var scope = _scopeProvider.CreateScope(autoComplete: true)) + using (var scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { foreach (var sourceItem in source) { @@ -329,7 +329,7 @@ namespace Umbraco.Cms.Core.Mapping // if there is a direct map, map if (map != null) { - using (var scope = _scopeProvider.CreateScope(autoComplete: true)) + using (var scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { map(source!, target!, context); } diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs index ac646d1c67..542494458e 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs @@ -26,7 +26,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install public class DatabaseBuilder { private readonly IUmbracoDatabaseFactory _databaseFactory; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IScopeAccessor _scopeAccessor; private readonly IRuntimeState _runtimeState; private readonly IKeyValueService _keyValueService; @@ -45,7 +45,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install /// Initializes a new instance of the class. /// public DatabaseBuilder( - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IScopeAccessor scopeAccessor, IUmbracoDatabaseFactory databaseFactory, IRuntimeState runtimeState, @@ -99,7 +99,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install public bool HasSomeNonDefaultUser() { - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { // look for the super user with default password var sql = _scopeAccessor.AmbientScope?.Database.SqlContext.Sql() @@ -122,7 +122,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install internal bool IsUmbracoInstalled() { - using (var scope = _scopeProvider.CreateScope(autoComplete: true)) + using (var scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { return _scopeAccessor.AmbientScope?.Database.IsUmbracoInstalled() ?? false; } @@ -208,7 +208,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install /// public DatabaseSchemaResult? ValidateSchema() { - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { var result = ValidateSchema(scope); scope.Complete(); @@ -216,7 +216,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install } } - private DatabaseSchemaResult? ValidateSchema(IScope scope) + private DatabaseSchemaResult? ValidateSchema(ICoreScope scope) { if (_databaseFactory.Initialized == false) return new DatabaseSchemaResult(); @@ -240,7 +240,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install /// public Result? CreateSchemaAndData() { - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { var result = CreateSchemaAndData(scope); scope.Complete(); @@ -248,7 +248,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Install } } - private Result? CreateSchemaAndData(IScope scope) + private Result? CreateSchemaAndData(ICoreScope scope) { try { diff --git a/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs b/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs index 8834c68191..a89f89c7bc 100644 --- a/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs +++ b/src/Umbraco.Infrastructure/Migrations/MigrationPlanExecutor.cs @@ -12,14 +12,14 @@ namespace Umbraco.Cms.Infrastructure.Migrations { public class MigrationPlanExecutor : IMigrationPlanExecutor { - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IScopeAccessor _scopeAccessor; private readonly ILoggerFactory _loggerFactory; private readonly IMigrationBuilder _migrationBuilder; private readonly ILogger _logger; public MigrationPlanExecutor( - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IScopeAccessor scopeAccessor, ILoggerFactory loggerFactory, IMigrationBuilder migrationBuilder) @@ -57,7 +57,7 @@ namespace Umbraco.Cms.Infrastructure.Migrations plan.ThrowOnUnknownInitialState(nextState); } - using (IScope scope = _scopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { // We want to suppress scope (service, etc...) notifications during a migration plan // execution. This is because if a package that doesn't have their migration plan diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs index afc4fdec81..15225b868a 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/Upgrader.cs @@ -36,12 +36,12 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade /// /// A scope provider. /// A key-value service. - public ExecutedMigrationPlan Execute(IMigrationPlanExecutor migrationPlanExecutor, IScopeProvider scopeProvider, IKeyValueService keyValueService) + public ExecutedMigrationPlan Execute(IMigrationPlanExecutor migrationPlanExecutor, ICoreScopeProvider scopeProvider, IKeyValueService keyValueService) { if (scopeProvider == null) throw new ArgumentNullException(nameof(scopeProvider)); if (keyValueService == null) throw new ArgumentNullException(nameof(keyValueService)); - using (IScope scope = scopeProvider.CreateScope()) + using (ICoreScope scope = scopeProvider.CreateCoreScope()) { // read current state var currentState = keyValueService.GetValue(StateValueKey); diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs index 6337ef1977..60492773b0 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/CacheInstructionRepository.cs @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement public CacheInstructionRepository(IScopeAccessor scopeAccessor) => _scopeAccessor = scopeAccessor; /// - private IDatabaseScope? AmbientScope => _scopeAccessor.AmbientScope; + private Scoping.IScope? AmbientScope => _scopeAccessor.AmbientScope; /// public int CountAll() diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs index 1a831db780..3a305a6371 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs @@ -43,7 +43,8 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement _shortStringHelper = shortStringHelper; } - private IDatabaseScope? AmbientScope => _scopeAccessor.AmbientScope; + private Scoping.IScope? AmbientScope => _scopeAccessor.AmbientScope; + private IUmbracoDatabase? Database => AmbientScope?.Database; private ISqlContext? SqlContext => AmbientScope?.SqlContext; diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/NotificationsRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/NotificationsRepository.cs index 892c079fc6..be42f7b74f 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/NotificationsRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/NotificationsRepository.cs @@ -21,7 +21,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement _scopeAccessor = scopeAccessor; } - private IDatabaseScope? AmbientScope => _scopeAccessor.AmbientScope; + private Scoping.IScope? AmbientScope => _scopeAccessor.AmbientScope; public IEnumerable? GetUsersNotifications(IEnumerable userIds, string? action, IEnumerable nodeIds, Guid objectType) { diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryBase.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryBase.cs index e3fda464f7..fdcf11304b 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryBase.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RepositoryBase.cs @@ -35,11 +35,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement /// /// Gets the AmbientScope /// - protected IDatabaseScope AmbientScope + protected IScope AmbientScope { get { - IDatabaseScope? scope = ScopeAccessor.AmbientScope; + IScope? scope = ScopeAccessor.AmbientScope; if (scope == null) { throw new InvalidOperationException("Cannot run a repository without an ambient scope."); diff --git a/src/Umbraco.Infrastructure/Scoping/HttpScopeReference.cs b/src/Umbraco.Infrastructure/Scoping/HttpScopeReference.cs index 2514944303..b75259c4f8 100644 --- a/src/Umbraco.Infrastructure/Scoping/HttpScopeReference.cs +++ b/src/Umbraco.Infrastructure/Scoping/HttpScopeReference.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. namespace Umbraco.Cms.Core.Scoping @@ -10,11 +10,11 @@ namespace Umbraco.Cms.Core.Scoping /// Registered as Scoped in DI (per request) internal class HttpScopeReference : IHttpScopeReference { - private readonly ScopeProvider _scopeProvider; + private readonly Infrastructure.Scoping.ScopeProvider _scopeProvider; private bool _disposedValue; private bool _registered = false; - public HttpScopeReference(ScopeProvider scopeProvider) => _scopeProvider = scopeProvider; + public HttpScopeReference(Infrastructure.Scoping.ScopeProvider scopeProvider) => _scopeProvider = scopeProvider; protected virtual void Dispose(bool disposing) { @@ -26,7 +26,7 @@ namespace Umbraco.Cms.Core.Scoping { // dispose the entire chain (if any) // reset (don't commit by default) - Scope? scope; + Infrastructure.Scoping.Scope? scope; while ((scope = _scopeProvider.AmbientScope) != null) { scope.Reset(); diff --git a/src/Umbraco.Infrastructure/Scoping/IDatabaseScope.cs b/src/Umbraco.Infrastructure/Scoping/IDatabaseScope.cs deleted file mode 100644 index aac5f48b4b..0000000000 --- a/src/Umbraco.Infrastructure/Scoping/IDatabaseScope.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Umbraco.Cms.Core.Scoping; -using Umbraco.Cms.Infrastructure.Persistence; - -namespace Umbraco.Cms.Infrastructure.Scoping -{ - public interface IDatabaseScope : IScope - { - /// - /// Gets the scope database. - /// - IUmbracoDatabase Database { get; } - - /// - /// Gets the Sql context. - /// - ISqlContext SqlContext { get; } - } -} diff --git a/src/Umbraco.Infrastructure/Scoping/IScope.cs b/src/Umbraco.Infrastructure/Scoping/IScope.cs new file mode 100644 index 0000000000..db86177f9f --- /dev/null +++ b/src/Umbraco.Infrastructure/Scoping/IScope.cs @@ -0,0 +1,17 @@ +using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Persistence; + +namespace Umbraco.Cms.Infrastructure.Scoping; + +public interface IScope : ICoreScope +{ + /// + /// Gets the scope database. + /// + IUmbracoDatabase Database { get; } + + /// + /// Gets the Sql context. + /// + ISqlContext SqlContext { get; } +} diff --git a/src/Umbraco.Infrastructure/Scoping/IScopeAccessor.cs b/src/Umbraco.Infrastructure/Scoping/IScopeAccessor.cs index c392e28f61..6849e8b3ed 100644 --- a/src/Umbraco.Infrastructure/Scoping/IScopeAccessor.cs +++ b/src/Umbraco.Infrastructure/Scoping/IScopeAccessor.cs @@ -6,6 +6,6 @@ namespace Umbraco.Cms.Infrastructure.Scoping /// Gets the ambient scope. /// /// Returns null if there is no ambient scope. - IDatabaseScope? AmbientScope { get; } + IScope? AmbientScope { get; } } } diff --git a/src/Umbraco.Infrastructure/Scoping/IScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/IScopeProvider.cs new file mode 100644 index 0000000000..c29ce56a82 --- /dev/null +++ b/src/Umbraco.Infrastructure/Scoping/IScopeProvider.cs @@ -0,0 +1,119 @@ +using System.Data; +using Umbraco.Cms.Core.Events; +using Umbraco.Cms.Core.Persistence.Querying; +using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Persistence; + +namespace Umbraco.Cms.Infrastructure.Scoping; + +/// +/// Provides scopes. +/// +public interface IScopeProvider : ICoreScopeProvider +{ + /// + ICoreScope ICoreScopeProvider.CreateCoreScope( + IsolationLevel isolationLevel, + RepositoryCacheMode repositoryCacheMode, + IEventDispatcher? eventDispatcher, + IScopedNotificationPublisher? scopedNotificationPublisher, + bool? scopeFileSystems, + bool callContext, + bool autoComplete) => + CreateScope( + isolationLevel, + repositoryCacheMode, + eventDispatcher, + scopedNotificationPublisher, + scopeFileSystems, + callContext, + autoComplete); + + /// + IQuery ICoreScopeProvider.CreateQuery() => + SqlContext.Query(); + + /// + /// Creates an ambient scope. + /// + /// The transaction isolation level. + /// The repositories cache mode. + /// An optional events dispatcher. + /// An optional notification publisher. + /// A value indicating whether to scope the filesystems. + /// A value indicating whether this scope should always be registered in the call context. + /// A value indicating whether this scope is auto-completed. + /// The created ambient scope. + /// + /// The created scope becomes the ambient scope. + /// If an ambient scope already exists, it becomes the parent of the created scope. + /// When the created scope is disposed, the parent scope becomes the ambient scope again. + /// Parameters must be specified on the outermost scope, or must be compatible with the parents. + /// Auto-completed scopes should be used for read-only operations ONLY. Do not use them if you do not + /// understand the associated issues, such as the scope being completed even though an exception is thrown. + /// + IScope CreateScope( + IsolationLevel isolationLevel = IsolationLevel.Unspecified, + RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + IEventDispatcher? eventDispatcher = null, + IScopedNotificationPublisher? scopedNotificationPublisher = null, + bool? scopeFileSystems = null, + bool callContext = false, + bool autoComplete = false); + + /// + /// Creates a detached scope. + /// + /// A detached scope. + /// The transaction isolation level. + /// The repositories cache mode. + /// An optional events dispatcher. + /// An option notification publisher. + /// A value indicating whether to scope the filesystems. + /// + /// A detached scope is not ambient and has no parent. + /// It is meant to be attached by . + /// + // TODO: This is not actually used apart from unit tests - I'm assuming it's maybe used by Deploy? + IScope CreateDetachedScope( + IsolationLevel isolationLevel = IsolationLevel.Unspecified, + RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + IEventDispatcher? eventDispatcher = null, + IScopedNotificationPublisher? scopedNotificationPublisher = null, + bool? scopeFileSystems = null); + + /// + /// Attaches a scope. + /// + /// The scope to attach. + /// A value indicating whether to force usage of call context. + /// + /// Only a scope created by can be attached. + /// + void AttachScope(IScope scope, bool callContext = false); + + /// + /// Detaches a scope. + /// + /// The detached scope. + /// + /// Only a scope previously attached by can be detached. + /// + IScope DetachScope(); + + /// + /// Gets the scope context. + /// + IScopeContext? Context { get; } + + /// + /// Gets the sql context. + /// + ISqlContext SqlContext { get; } + +#if DEBUG_SCOPES + + IEnumerable ScopeInfos { get; } + ScopeInfo GetScopeInfo(IScope scope); +#endif +} diff --git a/src/Umbraco.Infrastructure/Scoping/LegacyIScope.cs b/src/Umbraco.Infrastructure/Scoping/LegacyIScope.cs new file mode 100644 index 0000000000..e615a74afb --- /dev/null +++ b/src/Umbraco.Infrastructure/Scoping/LegacyIScope.cs @@ -0,0 +1,19 @@ +using System; +using Umbraco.Cms.Core.Events; + +// ReSharper disable once CheckNamespace +namespace Umbraco.Cms.Core.Scoping; + +[Obsolete("Please use Umbraco.Cms.Infrastructure.Scoping.IScope or Umbraco.Cms.Core.Scoping.ICoreScope instead.")] +public interface IScope : Infrastructure.Scoping.IScope +{ + /// + /// Gets the scope event messages. + /// + EventMessages Messages { get; } + + /// + /// Gets the scope event dispatcher. + /// + IEventDispatcher Events { get; } +} diff --git a/src/Umbraco.Infrastructure/Scoping/LegacyIScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/LegacyIScopeProvider.cs new file mode 100644 index 0000000000..371446e10c --- /dev/null +++ b/src/Umbraco.Infrastructure/Scoping/LegacyIScopeProvider.cs @@ -0,0 +1,9 @@ +using System; + +// ReSharper disable once CheckNamespace +namespace Umbraco.Cms.Core.Scoping; + +[Obsolete("Please use Umbraco.Cms.Infrastructure.Scoping.IScopeProvider or Umbraco.Cms.Core.Scoping.ICoreScopeProvider instead.")] +public interface IScopeProvider : Infrastructure.Scoping.IScopeProvider +{ +} diff --git a/src/Umbraco.Infrastructure/Scoping/Scope.cs b/src/Umbraco.Infrastructure/Scoping/Scope.cs index ecb47878fe..b37652012d 100644 --- a/src/Umbraco.Infrastructure/Scoping/Scope.cs +++ b/src/Umbraco.Infrastructure/Scoping/Scope.cs @@ -10,18 +10,22 @@ using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.DistributedLocking; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.IO; +using Umbraco.Cms.Core; +using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence; -using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Core.Collections; using Umbraco.Extensions; -namespace Umbraco.Cms.Core.Scoping +namespace Umbraco.Cms.Infrastructure.Scoping { /// /// Implements . /// /// Not thread-safe obviously. - internal class Scope : IDatabaseScope + internal class Scope : + ICoreScope, + IScope, + Core.Scoping.IScope { private readonly bool _autoComplete; private readonly CoreDebugSettings _coreDebugSettings; @@ -31,6 +35,7 @@ namespace Umbraco.Cms.Core.Scoping private readonly IsolationLevel _isolationLevel; private readonly object _lockQueueLocker = new(); private readonly ILogger _logger; + private readonly MediaFileManager _mediaFileManager; private readonly RepositoryCacheMode _repositoryCacheMode; private readonly bool? _scopeFileSystem; @@ -40,8 +45,10 @@ namespace Umbraco.Cms.Core.Scoping private IUmbracoDatabase? _database; private bool _disposed; + private IEventDispatcher? _eventDispatcher; private ICompletable? _fscope; + private EventMessages? _messages; private IsolatedCaches? _isolatedCaches; private IScopedNotificationPublisher? _notificationPublisher; @@ -59,6 +66,7 @@ namespace Umbraco.Cms.Core.Scoping private Scope( ScopeProvider scopeProvider, CoreDebugSettings coreDebugSettings, + MediaFileManager mediaFileManager, IEventAggregator eventAggregator, ILogger logger, FileSystems fileSystems, @@ -67,6 +75,7 @@ namespace Umbraco.Cms.Core.Scoping bool detachable, IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + IEventDispatcher? eventDispatcher = null, IScopedNotificationPublisher? notificationPublisher = null, bool? scopeFileSystems = null, bool callContext = false, @@ -74,12 +83,14 @@ namespace Umbraco.Cms.Core.Scoping { _scopeProvider = scopeProvider; _coreDebugSettings = coreDebugSettings; + _mediaFileManager = mediaFileManager; _eventAggregator = eventAggregator; _logger = logger; Context = scopeContext; _isolationLevel = isolationLevel; _repositoryCacheMode = repositoryCacheMode; + _eventDispatcher = eventDispatcher; _notificationPublisher = notificationPublisher; _scopeFileSystem = scopeFileSystems; _callContext = callContext; @@ -137,6 +148,12 @@ namespace Umbraco.Cms.Core.Scoping nameof(repositoryCacheMode)); } + // cannot specify a dispatcher! + if (_eventDispatcher != null) + { + throw new ArgumentException("Value cannot be specified on nested scope.", nameof(eventDispatcher)); + } + // Only the outermost scope can specify the notification publisher if (_notificationPublisher != null) { @@ -171,6 +188,7 @@ namespace Umbraco.Cms.Core.Scoping public Scope( ScopeProvider scopeProvider, CoreDebugSettings coreDebugSettings, + MediaFileManager mediaFileManager, IEventAggregator eventAggregator, ILogger logger, FileSystems fileSystems, @@ -178,13 +196,28 @@ namespace Umbraco.Cms.Core.Scoping IScopeContext? scopeContext, IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + IEventDispatcher? eventDispatcher = null, IScopedNotificationPublisher? scopedNotificationPublisher = null, bool? scopeFileSystems = null, bool callContext = false, bool autoComplete = false) - : this(scopeProvider, coreDebugSettings, eventAggregator, logger, fileSystems, null, - scopeContext, detachable, isolationLevel, repositoryCacheMode, - scopedNotificationPublisher, scopeFileSystems, callContext, autoComplete) + : this( + scopeProvider, + coreDebugSettings, + mediaFileManager, + eventAggregator, + logger, + fileSystems, + null, + scopeContext, + detachable, + isolationLevel, + repositoryCacheMode, + eventDispatcher, + scopedNotificationPublisher, + scopeFileSystems, + callContext, + autoComplete) { } @@ -192,23 +225,38 @@ namespace Umbraco.Cms.Core.Scoping public Scope( ScopeProvider scopeProvider, CoreDebugSettings coreDebugSettings, + MediaFileManager mediaFileManager, IEventAggregator eventAggregator, ILogger logger, FileSystems fileSystems, Scope parent, IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + IEventDispatcher? eventDispatcher = null, IScopedNotificationPublisher? notificationPublisher = null, bool? scopeFileSystems = null, bool callContext = false, bool autoComplete = false) - : this(scopeProvider, coreDebugSettings, eventAggregator, logger, fileSystems, parent, - null, false, isolationLevel, repositoryCacheMode, notificationPublisher, - scopeFileSystems, callContext, autoComplete) + : this( + scopeProvider, + coreDebugSettings, + mediaFileManager, + eventAggregator, + logger, + fileSystems, + parent, + null, + false, + isolationLevel, + repositoryCacheMode, + eventDispatcher, + notificationPublisher, + scopeFileSystems, + callContext, + autoComplete) { } - // a value indicating whether to force call-context public bool CallContext { @@ -378,19 +426,56 @@ namespace Umbraco.Cms.Core.Scoping // enter a transaction, as a scope implies a transaction, always try { - _database!.BeginTransaction(IsolationLevel); + _database.BeginTransaction(IsolationLevel); EnsureDbLocks(); return _database; } catch { - _database?.Dispose(); + _database.Dispose(); _database = null; throw; } } } + /// + public EventMessages Messages + { + get + { + EnsureNotDisposed(); + if (ParentScope != null) + { + return ParentScope.Messages; + } + + return _messages ??= new EventMessages(); + + // TODO: event messages? + // this may be a problem: the messages collection will be cleared at the end of the scope + // how shall we process it in controllers etc? if we don't want the global factory from v7? + // it'd need to be captured by the controller + // + // + rename // EventMessages = ServiceMessages or something + } + } + + /// + public IEventDispatcher Events + { + get + { + EnsureNotDisposed(); + if (ParentScope != null) + { + return ParentScope.Events; + } + + return _eventDispatcher ??= new QueuingEventDispatcher(_mediaFileManager); + } + } + public IScopedNotificationPublisher Notifications { get @@ -678,8 +763,8 @@ namespace Umbraco.Cms.Core.Scoping var builder = new StringBuilder(); builder.AppendLine( $"Lock counters aren't empty, suggesting a scope hasn't been properly disposed, parent id: {InstanceId}"); - WriteLockDictionaryToString(_readLocksDictionary, builder, "read locks"); - WriteLockDictionaryToString(_writeLocksDictionary, builder, "write locks"); + WriteLockDictionaryToString(_readLocksDictionary!, builder, "read locks"); + WriteLockDictionaryToString(_writeLocksDictionary!, builder, "write locks"); return builder.ToString(); } @@ -689,7 +774,7 @@ namespace Umbraco.Cms.Core.Scoping /// Lock dictionary to report on. /// String builder to write to. /// The name to report the dictionary as. - private void WriteLockDictionaryToString(Dictionary>? dict, StringBuilder builder, + private void WriteLockDictionaryToString(Dictionary> dict, StringBuilder builder, string dictName) { if (dict?.Count > 0) @@ -784,6 +869,7 @@ namespace Umbraco.Cms.Core.Scoping { if (onException == false) { + _eventDispatcher?.ScopeExit(completed); _notificationPublisher?.ScopeExit(completed); } } @@ -1026,8 +1112,8 @@ namespace Umbraco.Cms.Core.Scoping // We are the outermost scope, handle the lock request. LockInner( instanceId, - ref _readLocksDictionary, - ref _readLocks, + ref _readLocksDictionary!, + ref _readLocks!, ObtainReadLock, timeout, lockId); @@ -1060,8 +1146,8 @@ namespace Umbraco.Cms.Core.Scoping // We are the outermost scope, handle the lock request. LockInner( instanceId, - ref _writeLocksDictionary, - ref _writeLocks, + ref _writeLocksDictionary!, + ref _writeLocks!, ObtainWriteLock, timeout, lockId); @@ -1081,8 +1167,8 @@ namespace Umbraco.Cms.Core.Scoping /// Lock identifier. private void LockInner( Guid instanceId, - ref Dictionary>? locks, - ref HashSet? locksSet, + ref Dictionary> locks, + ref HashSet locksSet, Action obtainLock, TimeSpan? timeout, int lockId) @@ -1104,7 +1190,7 @@ namespace Umbraco.Cms.Core.Scoping { // Something went wrong and we didn't get the lock // Since we at this point have determined that we haven't got any lock with an ID of LockID, it's safe to completely remove it instead of decrementing. - locks?[instanceId].Remove(lockId); + locks[instanceId].Remove(lockId); // It needs to be removed from the HashSet as well, because that's how we determine to acquire a lock. locksSet.Remove(lockId); @@ -1118,7 +1204,7 @@ namespace Umbraco.Cms.Core.Scoping /// Lock object identifier to lock. /// TimeSpan specifying the timout period. private void ObtainReadLock(int lockId, TimeSpan? timeout) - => _acquiredLocks?.Enqueue(_scopeProvider.DistributedLockingMechanismFactory.DistributedLockingMechanism!.ReadLock(lockId, timeout)); + => _acquiredLocks!.Enqueue(_scopeProvider.DistributedLockingMechanismFactory.DistributedLockingMechanism.ReadLock(lockId, timeout)); /// /// Obtains a write lock with a custom timeout. @@ -1126,6 +1212,6 @@ namespace Umbraco.Cms.Core.Scoping /// Lock object identifier to lock. /// TimeSpan specifying the timout period. private void ObtainWriteLock(int lockId, TimeSpan? timeout) - => _acquiredLocks?.Enqueue(_scopeProvider.DistributedLockingMechanismFactory.DistributedLockingMechanism!.WriteLock(lockId, timeout)); + => _acquiredLocks!.Enqueue(_scopeProvider.DistributedLockingMechanismFactory.DistributedLockingMechanism.WriteLock(lockId, timeout)); } } diff --git a/src/Umbraco.Infrastructure/Scoping/ScopeContextualBase.cs b/src/Umbraco.Infrastructure/Scoping/ScopeContextualBase.cs index 19a25f8d8f..92c395932e 100644 --- a/src/Umbraco.Infrastructure/Scoping/ScopeContextualBase.cs +++ b/src/Umbraco.Infrastructure/Scoping/ScopeContextualBase.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Umbraco.Cms.Core.Scoping { @@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Scoping /// /// /// - public static T? Get(IScopeProvider scopeProvider, string key, Func ctor) + public static T? Get(ICoreScopeProvider scopeProvider, string key, Func ctor) where T : ScopeContextualBase { // no scope context = create a non-scoped object diff --git a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs index 901fec317c..6fbfc170b0 100644 --- a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs +++ b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs @@ -8,30 +8,33 @@ using Umbraco.Cms.Core.IO; using Umbraco.Cms.Infrastructure.Persistence; using CoreDebugSettings = Umbraco.Cms.Core.Configuration.Models.CoreDebugSettings; using Umbraco.Extensions; -using System.Collections.Generic; using System.Collections.Concurrent; using System.Threading; using Umbraco.Cms.Core.DistributedLocking; -using Umbraco.Cms.Core.Persistence.Querying; -using Umbraco.Cms.Infrastructure.Scoping; +using Umbraco.Cms.Core.Scoping; #if DEBUG_SCOPES using System.Linq; using System.Text; #endif -namespace Umbraco.Cms.Core.Scoping +namespace Umbraco.Cms.Infrastructure.Scoping { /// /// Implements . /// - internal class ScopeProvider : IScopeProvider, IScopeAccessor + internal class ScopeProvider : + ICoreScopeProvider, + IScopeProvider, + Core.Scoping.IScopeProvider, + IScopeAccessor { private readonly ILogger _logger; private readonly ILoggerFactory _loggerFactory; private readonly IRequestCache _requestCache; private readonly FileSystems _fileSystems; private CoreDebugSettings _coreDebugSettings; + private readonly MediaFileManager _mediaFileManager; private static readonly AsyncLocal> s_scopeStack = new AsyncLocal>(); private static readonly AsyncLocal> s_scopeContextStack = new AsyncLocal>(); private static readonly string s_scopeItemKey = typeof(Scope).FullName!; @@ -43,6 +46,7 @@ namespace Umbraco.Cms.Core.Scoping IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, IOptionsMonitor coreDebugSettings, + MediaFileManager mediaFileManager, ILoggerFactory loggerFactory, IRequestCache requestCache, IEventAggregator eventAggregator) @@ -51,6 +55,7 @@ namespace Umbraco.Cms.Core.Scoping DatabaseFactory = databaseFactory; _fileSystems = fileSystems; _coreDebugSettings = coreDebugSettings.CurrentValue; + _mediaFileManager = mediaFileManager; _logger = loggerFactory.CreateLogger(); _loggerFactory = loggerFactory; _requestCache = requestCache; @@ -67,8 +72,6 @@ namespace Umbraco.Cms.Core.Scoping public ISqlContext SqlContext => DatabaseFactory.SqlContext; - public IQuery CreateQuery() => SqlContext.Query(); - #region Context private void MoveHttpContextScopeToCallContext() @@ -292,7 +295,7 @@ namespace Umbraco.Cms.Core.Scoping #region Ambient Scope - IDatabaseScope? IScopeAccessor.AmbientScope => AmbientScope; + IScope? IScopeAccessor.AmbientScope => AmbientScope; /// /// Gets or set the Ambient (Current) for the current execution context. @@ -394,9 +397,10 @@ namespace Umbraco.Cms.Core.Scoping public IScope CreateDetachedScope( IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + IEventDispatcher? eventDispatcher = null, IScopedNotificationPublisher? scopedNotificationPublisher = null, bool? scopeFileSystems = null) - => new Scope(this, _coreDebugSettings, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, true, null, isolationLevel, repositoryCacheMode, scopedNotificationPublisher, scopeFileSystems); + => new Scope(this, _coreDebugSettings, _mediaFileManager, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, true, null, isolationLevel, repositoryCacheMode, eventDispatcher, scopedNotificationPublisher, scopeFileSystems); /// public void AttachScope(IScope other, bool callContext = false) @@ -465,6 +469,7 @@ namespace Umbraco.Cms.Core.Scoping public IScope CreateScope( IsolationLevel isolationLevel = IsolationLevel.Unspecified, RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + IEventDispatcher? eventDispatcher = null, IScopedNotificationPublisher? notificationPublisher = null, bool? scopeFileSystems = null, bool callContext = false, @@ -475,7 +480,8 @@ namespace Umbraco.Cms.Core.Scoping { IScopeContext? ambientContext = AmbientContext; ScopeContext? newContext = ambientContext == null ? new ScopeContext() : null; - var scope = new Scope(this, _coreDebugSettings, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, false, newContext, isolationLevel, repositoryCacheMode, notificationPublisher, scopeFileSystems, callContext, autoComplete); + var scope = new Scope(this, _coreDebugSettings, _mediaFileManager, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, false, newContext, isolationLevel, repositoryCacheMode, eventDispatcher, notificationPublisher, scopeFileSystems, callContext, autoComplete); + // assign only if scope creation did not throw! PushAmbientScope(scope); if (newContext != null) @@ -485,7 +491,7 @@ namespace Umbraco.Cms.Core.Scoping return scope; } - var nested = new Scope(this, _coreDebugSettings, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, ambientScope, isolationLevel, repositoryCacheMode, notificationPublisher, scopeFileSystems, callContext, autoComplete); + var nested = new Scope(this, _coreDebugSettings, _mediaFileManager, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, ambientScope, isolationLevel, repositoryCacheMode, eventDispatcher, notificationPublisher, scopeFileSystems, callContext, autoComplete); PushAmbientScope(nested); return nested; } diff --git a/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs b/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs index f48a796867..c32362d56c 100644 --- a/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs +++ b/src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Security /// public class BackOfficeUserStore : UmbracoUserStore>, IUserSessionStore { - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IUserService _userService; private readonly IEntityService _entityService; private readonly IExternalLoginWithKeyService _externalLoginService; @@ -42,7 +42,7 @@ namespace Umbraco.Cms.Core.Security /// [ActivatorUtilitiesConstructor] public BackOfficeUserStore( - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IUserService userService, IEntityService entityService, IExternalLoginWithKeyService externalLoginService, @@ -67,7 +67,7 @@ namespace Umbraco.Cms.Core.Security [Obsolete("Use non obsolete ctor")] public BackOfficeUserStore( - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IUserService userService, IEntityService entityService, IExternalLoginWithKeyService externalLoginService, @@ -91,7 +91,7 @@ namespace Umbraco.Cms.Core.Security [Obsolete("Use non obsolete ctor")] public BackOfficeUserStore( - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IUserService userService, IEntityService entityService, IExternalLoginService externalLoginService, @@ -205,7 +205,7 @@ namespace Umbraco.Cms.Core.Security throw new InvalidOperationException("The user id must be an integer to work with the Umbraco"); } - using (IScope scope = _scopeProvider.CreateScope()) + using (ICoreScope scope = _scopeProvider.CreateCoreScope()) { IUser? found = _userService.GetUserById(asInt); if (found != null) diff --git a/src/Umbraco.Infrastructure/Security/MemberUserStore.cs b/src/Umbraco.Infrastructure/Security/MemberUserStore.cs index 1211a2c05f..3d8f3447d5 100644 --- a/src/Umbraco.Infrastructure/Security/MemberUserStore.cs +++ b/src/Umbraco.Infrastructure/Security/MemberUserStore.cs @@ -26,7 +26,7 @@ namespace Umbraco.Cms.Core.Security private const string GenericIdentityErrorCode = "IdentityErrorUserStore"; private readonly IMemberService _memberService; private readonly IUmbracoMapper _mapper; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; private readonly IExternalLoginWithKeyService _externalLoginService; private readonly ITwoFactorLoginService _twoFactorLoginService; @@ -45,7 +45,7 @@ namespace Umbraco.Cms.Core.Security public MemberUserStore( IMemberService memberService, IUmbracoMapper mapper, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IdentityErrorDescriber describer, IPublishedSnapshotAccessor publishedSnapshotAccessor, IExternalLoginWithKeyService externalLoginService, @@ -65,7 +65,7 @@ namespace Umbraco.Cms.Core.Security public MemberUserStore( IMemberService memberService, IUmbracoMapper mapper, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IdentityErrorDescriber describer, IPublishedSnapshotAccessor publishedSnapshotAccessor, IExternalLoginService externalLoginService) @@ -78,7 +78,7 @@ namespace Umbraco.Cms.Core.Security public MemberUserStore( IMemberService memberService, IUmbracoMapper mapper, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IdentityErrorDescriber describer, IPublishedSnapshotAccessor publishedSnapshotAccessor) : this(memberService, mapper, scopeProvider, describer, publishedSnapshotAccessor, StaticServiceProvider.Instance.GetRequiredService(), StaticServiceProvider.Instance.GetRequiredService()) @@ -98,7 +98,7 @@ namespace Umbraco.Cms.Core.Security throw new ArgumentNullException(nameof(user)); } - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); // create member IMember memberEntity = _memberService.CreateMember( @@ -175,7 +175,7 @@ namespace Umbraco.Cms.Core.Security throw new InvalidOperationException("The user id must be an integer to work with the Umbraco"); } - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); IMember? found = _memberService.GetById(asInt); if (found != null) diff --git a/src/Umbraco.Infrastructure/Services/IdKeyMap.cs b/src/Umbraco.Infrastructure/Services/IdKeyMap.cs index c851408a6f..2ca1508d0b 100644 --- a/src/Umbraco.Infrastructure/Services/IdKeyMap.cs +++ b/src/Umbraco.Infrastructure/Services/IdKeyMap.cs @@ -10,14 +10,14 @@ namespace Umbraco.Cms.Core.Services { public class IdKeyMap : IIdKeyMap,IDisposable { - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IScopeAccessor _scopeAccessor; private readonly ReaderWriterLockSlim _locker = new ReaderWriterLockSlim(); private readonly Dictionary> _id2Key = new Dictionary>(); private readonly Dictionary> _key2Id = new Dictionary>(); - public IdKeyMap(IScopeProvider scopeProvider, IScopeAccessor scopeAccessor) + public IdKeyMap(ICoreScopeProvider scopeProvider, IScopeAccessor scopeAccessor) { _scopeProvider = scopeProvider; _scopeAccessor = scopeAccessor; @@ -81,7 +81,7 @@ namespace Umbraco.Cms.Core.Services // don't if not empty if (_key2Id.Count > 0) return; - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { // populate content and media items var types = new[] { Constants.ObjectTypes.Document, Constants.ObjectTypes.Media }; @@ -168,7 +168,7 @@ namespace Umbraco.Cms.Core.Services if (val == null) { - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { //if it's unknown don't include the nodeObjectType in the query if (umbracoObjectType == UmbracoObjectTypes.Unknown) @@ -256,7 +256,7 @@ namespace Umbraco.Cms.Core.Services if (val == null) { - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { //if it's unknown don't include the nodeObjectType in the query if (umbracoObjectType == UmbracoObjectTypes.Unknown) diff --git a/src/Umbraco.Infrastructure/Services/Implement/AuditService.cs b/src/Umbraco.Infrastructure/Services/Implement/AuditService.cs index e779161f06..339ac1adee 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/AuditService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/AuditService.cs @@ -17,7 +17,7 @@ namespace Umbraco.Cms.Core.Services.Implement private readonly IAuditRepository _auditRepository; private readonly IAuditEntryRepository _auditEntryRepository; - public AuditService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + public AuditService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IAuditRepository auditRepository, IAuditEntryRepository auditEntryRepository) : base(provider, loggerFactory, eventMessagesFactory) { @@ -28,7 +28,7 @@ namespace Umbraco.Cms.Core.Services.Implement public void Add(AuditType type, int userId, int objectId, string? entityType, string comment, string? parameters = null) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _auditRepository.Save(new AuditItem(objectId, type, userId, entityType, comment, parameters)); scope.Complete(); @@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.Services.Implement public IEnumerable? GetLogs(int objectId) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var result = _auditRepository.Get(Query().Where(x => x.Id == objectId)); scope.Complete(); @@ -47,7 +47,7 @@ namespace Umbraco.Cms.Core.Services.Implement public IEnumerable GetUserLogs(int userId, AuditType type, DateTime? sinceDate = null) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var result = sinceDate.HasValue == false ? _auditRepository.Get(type, Query().Where(x => x.UserId == userId)) @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Core.Services.Implement public IEnumerable GetLogs(AuditType type, DateTime? sinceDate = null) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var result = sinceDate.HasValue == false ? _auditRepository.Get(type, Query()) @@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.Services.Implement public void CleanLogs(int maximumAgeOfLogsInMinutes) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _auditRepository.CleanLogs(maximumAgeOfLogsInMinutes); scope.Complete(); @@ -110,7 +110,7 @@ namespace Umbraco.Cms.Core.Services.Implement return Enumerable.Empty(); } - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.Id == entityId); @@ -147,7 +147,7 @@ namespace Umbraco.Cms.Core.Services.Implement return Enumerable.Empty(); } - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.UserId == userId); @@ -190,7 +190,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (_isAvailable.Value == false) return entry; - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { _auditEntryRepository.Save(entry); scope.Complete(); @@ -204,7 +204,7 @@ namespace Umbraco.Cms.Core.Services.Implement { if (_isAvailable.Value == false) return Enumerable.Empty(); - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _auditEntryRepository.GetMany(); } @@ -219,7 +219,7 @@ namespace Umbraco.Cms.Core.Services.Implement return Enumerable.Empty(); } - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _auditEntryRepository.GetPage(pageIndex, pageCount, out records); } @@ -230,7 +230,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// private bool DetermineIsAvailable() { - using (ScopeProvider.CreateScope(autoComplete: true)) + using (ScopeProvider.CreateCoreScope(autoComplete: true)) { return _auditEntryRepository.IsAvailable(); } diff --git a/src/Umbraco.Infrastructure/Services/Implement/CacheInstructionService.cs b/src/Umbraco.Infrastructure/Services/Implement/CacheInstructionService.cs index cac2ec603e..1a6cc125cf 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/CacheInstructionService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/CacheInstructionService.cs @@ -32,7 +32,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// Initializes a new instance of the class. /// public CacheInstructionService( - IScopeProvider provider, + ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, ICacheInstructionRepository cacheInstructionRepository, @@ -50,7 +50,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// public bool IsColdBootRequired(int lastId) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { if (lastId <= 0) { @@ -77,7 +77,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// public bool IsInstructionCountOverLimit(int lastId, int limit, out int count) { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // Check for how many instructions there are to process, each row contains a count of the number of instructions contained in each // row so we will sum these numbers to get the actual count. @@ -89,7 +89,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// public int GetMaxInstructionId() { - using (IScope scope = ScopeProvider.CreateScope(autoComplete: true)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _cacheInstructionRepository.GetMaxId(); } @@ -100,7 +100,7 @@ namespace Umbraco.Cms.Core.Services.Implement { CacheInstruction entity = CreateCacheInstruction(instructions, localIdentity); - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { _cacheInstructionRepository.Add(entity); scope.Complete(); @@ -111,7 +111,7 @@ namespace Umbraco.Cms.Core.Services.Implement public void DeliverInstructionsInBatches(IEnumerable instructions, string localIdentity) { // Write the instructions but only create JSON blobs with a max instruction count equal to MaxProcessingInstructionCount. - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { foreach (IEnumerable instructionsBatch in instructions.InGroupsOf(_globalSettings.DatabaseServerMessenger.MaxProcessingInstructionCount)) { @@ -136,7 +136,7 @@ namespace Umbraco.Cms.Core.Services.Implement int lastId) { using (_profilingLogger.DebugDuration("Syncing from database...")) - using (IScope scope = ScopeProvider.CreateScope()) + using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { var numberOfInstructionsProcessed = ProcessDatabaseInstructions(cacheRefreshers, cancellationToken, localIdentity, ref lastId); diff --git a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs index cfdd7fcc04..f936144769 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/DataTypeService.cs @@ -35,7 +35,7 @@ namespace Umbraco.Cms.Core.Services.Implement public DataTypeService( IDataValueEditorFactory dataValueEditorFactory, - IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, + ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IDataTypeRepository dataTypeRepository, IDataTypeContainerRepository dataTypeContainerRepository, IAuditRepository auditRepository, IEntityRepository entityRepository, IContentTypeRepository contentTypeRepository, IIOHelper ioHelper, ILocalizedTextService localizedTextService, ILocalizationService localizationService, @@ -61,7 +61,7 @@ namespace Umbraco.Cms.Core.Services.Implement public Attempt?> CreateContainer(int parentId, Guid key, string name, int userId = Cms.Core.Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { try { @@ -98,7 +98,7 @@ namespace Umbraco.Cms.Core.Services.Implement public EntityContainer? GetContainer(int containerId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _dataTypeContainerRepository.Get(containerId); } @@ -106,7 +106,7 @@ namespace Umbraco.Cms.Core.Services.Implement public EntityContainer? GetContainer(Guid containerId) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _dataTypeContainerRepository.Get(containerId); } @@ -114,7 +114,7 @@ namespace Umbraco.Cms.Core.Services.Implement public IEnumerable GetContainers(string name, int level) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _dataTypeContainerRepository.Get(name, level); } @@ -136,7 +136,7 @@ namespace Umbraco.Cms.Core.Services.Implement public IEnumerable? GetContainers(int[] containerIds) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { return _dataTypeContainerRepository.GetMany(containerIds); } @@ -158,7 +158,7 @@ namespace Umbraco.Cms.Core.Services.Implement return OperationResult.Attempt.Fail(evtMsgs, ex); } - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var savingEntityContainerNotification = new EntityContainerSavingNotification(container, evtMsgs); if (scope.Notifications.PublishCancelable(savingEntityContainerNotification)) @@ -180,7 +180,7 @@ namespace Umbraco.Cms.Core.Services.Implement public Attempt DeleteContainer(int containerId, int userId = Cms.Core.Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var container = _dataTypeContainerRepository.Get(containerId); if (container == null) return OperationResult.Attempt.NoOperation(evtMsgs); @@ -214,7 +214,7 @@ namespace Umbraco.Cms.Core.Services.Implement public Attempt?> RenameContainer(int id, string name, int userId = Cms.Core.Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { try { @@ -256,7 +256,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// public IDataType? GetDataType(string name) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var dataType = _dataTypeRepository.Get(Query().Where(x => x.Name == name))?.FirstOrDefault(); ConvertMissingEditorOfDataTypeToLabel(dataType); @@ -271,7 +271,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// public IDataType? GetDataType(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var dataType = _dataTypeRepository.Get(id); ConvertMissingEditorOfDataTypeToLabel(dataType); @@ -286,7 +286,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// public IDataType? GetDataType(Guid id) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.Key == id); var dataType = _dataTypeRepository.Get(query)?.FirstOrDefault(); @@ -302,7 +302,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// Collection of objects with a matching control id public IEnumerable? GetByEditorAlias(string propertyEditorAlias) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var query = Query().Where(x => x.EditorAlias == propertyEditorAlias); var dataType = _dataTypeRepository.Get(query); @@ -322,7 +322,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// An enumerable list of objects public IEnumerable? GetAll(params int[] ids) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { var dataTypes = _dataTypeRepository.GetMany(ids); if (dataTypes is null) @@ -362,7 +362,7 @@ namespace Umbraco.Cms.Core.Services.Implement var evtMsgs = EventMessagesFactory.Get(); var moveInfo = new List>(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var moveEventInfo = new MoveEventInfo(toMove, toMove.Path, parentId); @@ -408,7 +408,7 @@ namespace Umbraco.Cms.Core.Services.Implement var evtMsgs = EventMessagesFactory.Get(); dataType.CreatorId = userId; - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var saveEventArgs = new SaveEventArgs(dataType); @@ -448,7 +448,7 @@ namespace Umbraco.Cms.Core.Services.Implement var evtMsgs = EventMessagesFactory.Get(); var dataTypeDefinitionsA = dataTypeDefinitions.ToArray(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var savingDataTypeNotification = new DataTypeSavingNotification(dataTypeDefinitions, evtMsgs); if (scope.Notifications.PublishCancelable(savingDataTypeNotification)) @@ -483,7 +483,7 @@ namespace Umbraco.Cms.Core.Services.Implement public void Delete(IDataType dataType, int userId = Cms.Core.Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { var deletingDataTypeNotification = new DataTypeDeletingNotification(dataType, evtMsgs); if (scope.Notifications.PublishCancelable(deletingDataTypeNotification)) @@ -534,7 +534,7 @@ namespace Umbraco.Cms.Core.Services.Implement public IReadOnlyDictionary> GetReferences(int id) { - using (var scope = ScopeProvider.CreateScope(autoComplete:true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete:true)) { return _dataTypeRepository.FindUsages(id); } diff --git a/src/Umbraco.Infrastructure/Services/Implement/ServerRegistrationService.cs b/src/Umbraco.Infrastructure/Services/Implement/ServerRegistrationService.cs index 5f73281962..38ec668c85 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/ServerRegistrationService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/ServerRegistrationService.cs @@ -27,7 +27,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// Initializes a new instance of the class. /// public ServerRegistrationService( - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IServerRegistrationRepository serverRegistrationRepository, @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Services.Implement public void TouchServer(string serverAddress, TimeSpan staleTimeout) { var serverIdentity = GetCurrentServerIdentity(); - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.Servers); @@ -95,7 +95,7 @@ namespace Umbraco.Cms.Core.Services.Implement { // because the repository caches "all" and has queries disabled... - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.Servers); @@ -116,7 +116,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// The time after which a server is considered stale. public void DeactiveStaleServers(TimeSpan staleTimeout) { - using (var scope = ScopeProvider.CreateScope()) + using (var scope = ScopeProvider.CreateCoreScope()) { scope.WriteLock(Cms.Core.Constants.Locks.Servers); _serverRegistrationRepository.DeactiveStaleServers(staleTimeout); @@ -146,7 +146,7 @@ namespace Umbraco.Cms.Core.Services.Implement /// from the database. public IEnumerable GetServers(bool refresh = false) { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) + using (var scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { scope.ReadLock(Cms.Core.Constants.Locks.Servers); if (refresh) diff --git a/src/Umbraco.Infrastructure/Services/Implement/TwoFactorLoginService.cs b/src/Umbraco.Infrastructure/Services/Implement/TwoFactorLoginService.cs index d4c91c34c4..7a4feb91fb 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/TwoFactorLoginService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/TwoFactorLoginService.cs @@ -18,7 +18,7 @@ namespace Umbraco.Cms.Core.Services public class TwoFactorLoginService : ITwoFactorLoginService2 { private readonly ITwoFactorLoginRepository _twoFactorLoginRepository; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly IOptions _identityOptions; private readonly IOptions _backOfficeIdentityOptions; private readonly IDictionary _twoFactorSetupGenerators; @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.Services /// public TwoFactorLoginService( ITwoFactorLoginRepository twoFactorLoginRepository, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IEnumerable twoFactorSetupGenerators, IOptions identityOptions, IOptions backOfficeIdentityOptions, @@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Services [Obsolete("Use ctor with all params - This will be removed in v11")] public TwoFactorLoginService( ITwoFactorLoginRepository twoFactorLoginRepository, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IEnumerable twoFactorSetupGenerators, IOptions identityOptions, IOptions backOfficeIdentityOptions) @@ -63,7 +63,7 @@ namespace Umbraco.Cms.Core.Services /// public async Task DeleteUserLoginsAsync(Guid userOrMemberKey) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); await _twoFactorLoginRepository.DeleteUserLoginsAsync(userOrMemberKey); } @@ -125,7 +125,7 @@ namespace Umbraco.Cms.Core.Services private async Task> GetEnabledProviderNamesAsync(Guid userOrMemberKey) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); var providersOnUser = (await _twoFactorLoginRepository.GetByUserOrMemberKeyAsync(userOrMemberKey)) .Select(x => x.ProviderName).ToArray(); @@ -163,7 +163,7 @@ namespace Umbraco.Cms.Core.Services /// public async Task GetSecretForUserAndProviderAsync(Guid userOrMemberKey, string providerName) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); return (await _twoFactorLoginRepository.GetByUserOrMemberKeyAsync(userOrMemberKey)).FirstOrDefault(x => x.ProviderName == providerName)?.Secret; } @@ -194,7 +194,7 @@ namespace Umbraco.Cms.Core.Services /// public async Task DisableAsync(Guid userOrMemberKey, string providerName) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); return await _twoFactorLoginRepository.DeleteUserLoginsAsync(userOrMemberKey, providerName); } @@ -212,7 +212,7 @@ namespace Umbraco.Cms.Core.Services /// public Task SaveAsync(TwoFactorLogin twoFactorLogin) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); _twoFactorLoginRepository.Save(twoFactorLogin); return Task.CompletedTask; diff --git a/src/Umbraco.PublishedCache.NuCache/ContentStore.cs b/src/Umbraco.PublishedCache.NuCache/ContentStore.cs index b86c9e681b..da1157d613 100644 --- a/src/Umbraco.PublishedCache.NuCache/ContentStore.cs +++ b/src/Umbraco.PublishedCache.NuCache/ContentStore.cs @@ -136,7 +136,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache // gets a scope contextual representing a locked writer to the dictionary // TODO: GetScopedWriter? should the dict have a ref onto the scope provider? - public IDisposable? GetScopedWriteLock(IScopeProvider scopeProvider) + public IDisposable? GetScopedWriteLock(ICoreScopeProvider scopeProvider) { return ScopeContextualBase.Get(scopeProvider, _instanceId, scoped => new ScopedWriteLock(this, scoped)); } diff --git a/src/Umbraco.PublishedCache.NuCache/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.PublishedCache.NuCache/DependencyInjection/UmbracoBuilderExtensions.cs index 60face6428..13b79fb1a1 100644 --- a/src/Umbraco.PublishedCache.NuCache/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.PublishedCache.NuCache/DependencyInjection/UmbracoBuilderExtensions.cs @@ -43,7 +43,7 @@ namespace Umbraco.Extensions // TODO: Gotta wonder how much this does actually improve perf? It's a lot of weird code to make this happen so hope it's worth it builder.Services.AddUnique(factory => { - var idkSvc = new IdKeyMap(factory.GetRequiredService(), factory.GetRequiredService()); + var idkSvc = new IdKeyMap(factory.GetRequiredService(), factory.GetRequiredService()); if (factory.GetRequiredService() is PublishedSnapshotService publishedSnapshotService) { idkSvc.SetMapper(UmbracoObjectTypes.Document, id => publishedSnapshotService.GetDocumentUid(id), uid => publishedSnapshotService.GetDocumentId(uid)); diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs index 583ffa2799..70d48ec000 100644 --- a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs +++ b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs @@ -698,7 +698,7 @@ AND cmsContentNu.nodeId IS NULL } } - public ContentNodeKit GetMediaSource(IDatabaseScope scope, int id) + public ContentNodeKit GetMediaSource(Scoping.IScope scope, int id) { var sql = SqlMediaSourcesSelect() .Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Media)) diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs index 18aa7f1658..98033918ec 100644 --- a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs +++ b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs @@ -25,7 +25,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence public NuCacheContentService( INuCacheContentRepository repository, IKeyValueService keyValueService, - IScopeProvider provider, + ICoreScopeProvider provider, ILoggerFactory loggerFactory, IProfilingLogger profilingLogger, IEventMessagesFactory eventMessagesFactory, @@ -119,7 +119,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence IReadOnlyCollection? mediaTypeIds = null, IReadOnlyCollection? memberTypeIds = null) { - using (IScope scope = ScopeProvider.CreateScope(repositoryCacheMode: RepositoryCacheMode.Scoped)) + using (ICoreScope scope = ScopeProvider.CreateCoreScope(repositoryCacheMode: RepositoryCacheMode.Scoped)) { scope.ReadLock(Constants.Locks.ContentTree); @@ -139,7 +139,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence /// public bool VerifyContentDbCache() { - using IScope scope = ScopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); scope.ReadLock(Constants.Locks.ContentTree); return _repository.VerifyContentDbCache(); } @@ -147,7 +147,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence /// public bool VerifyMediaDbCache() { - using IScope scope = ScopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); scope.ReadLock(Constants.Locks.MediaTree); return _repository.VerifyMediaDbCache(); } @@ -155,7 +155,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache.Persistence /// public bool VerifyMemberDbCache() { - using IScope scope = ScopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true); scope.ReadLock(Constants.Locks.MemberTree); return _repository.VerifyMemberDbCache(); } diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index 2221cdd7d2..2b51a468bc 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; private readonly IVariationContextAccessor _variationContextAccessor; private readonly IProfilingLogger _profilingLogger; - private readonly IScopeProvider _scopeProvider; + private readonly Scoping.IScopeProvider _scopeProvider; private readonly INuCacheContentService _publishedContentService; private readonly ILogger _logger; private readonly ILoggerFactory _loggerFactory; @@ -85,7 +85,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache IVariationContextAccessor variationContextAccessor, IProfilingLogger profilingLogger, ILoggerFactory loggerFactory, - IScopeProvider scopeProvider, + Scoping.IScopeProvider scopeProvider, INuCacheContentService publishedContentService, IDefaultCultureAccessor defaultCultureAccessor, IOptions globalSettings, diff --git a/src/Umbraco.PublishedCache.NuCache/SnapDictionary.cs b/src/Umbraco.PublishedCache.NuCache/SnapDictionary.cs index 7437527d2a..cc2c0318f5 100644 --- a/src/Umbraco.PublishedCache.NuCache/SnapDictionary.cs +++ b/src/Umbraco.PublishedCache.NuCache/SnapDictionary.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; @@ -108,7 +108,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache // the dict is write-locked until the write-lock is released // which happens when it is disposed (non-scoped) // or when the scope context exits (scoped) - public IDisposable? GetScopedWriteLock(IScopeProvider scopeProvider) + public IDisposable? GetScopedWriteLock(ICoreScopeProvider scopeProvider) { return ScopeContextualBase.Get(scopeProvider, _instanceId, scoped => new ScopedWriteLock(this, scoped)); } diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs index 66c103b810..e1374ea56d 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs @@ -65,7 +65,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers private readonly IContentVersionService _contentVersionService; private readonly Lazy> _allLangs; private readonly ILogger _logger; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; public object? Domains { get; private set; } @@ -90,7 +90,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers ActionCollection actionCollection, ISqlContext sqlContext, IJsonSerializer serializer, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, IAuthorizationService authorizationService, IContentVersionService contentVersionService) : base(cultureDictionary, loggerFactory, shortStringHelper, eventMessages, localizedTextService, serializer) @@ -392,7 +392,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers public ActionResult> GetEmptyByAliases(ContentTypesByAliases contentTypesByAliases) { // It's important to do this operation within a scope to reduce the amount of readlock queries. - using var scope = _scopeProvider.CreateScope(autoComplete: true); + using var scope = _scopeProvider.CreateCoreScope(autoComplete: true); var contentTypes = contentTypesByAliases.ContentTypeAliases?.Select(alias => _contentTypeService.Get(alias)).WhereNotNull(); return GetEmpties(contentTypes, contentTypesByAliases.ParentId).ToDictionary(x => x.ContentTypeAlias); } @@ -405,7 +405,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers [OutgoingEditorModelEvent] public ActionResult GetEmptyByKey(Guid contentTypeKey, int parentId) { - using (var scope = _scopeProvider.CreateScope()) + using (var scope = _scopeProvider.CreateCoreScope()) { var contentType = _contentTypeService.Get(contentTypeKey); if (contentType == null) @@ -497,7 +497,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers private ActionResult> GetEmptyByKeysInternal(Guid[]? contentTypeKeys, int parentId) { - using var scope = _scopeProvider.CreateScope(autoComplete: true); + using var scope = _scopeProvider.CreateCoreScope(autoComplete: true); var contentTypes = _contentTypeService.GetAll(contentTypeKeys).ToList(); return GetEmpties(contentTypes, parentId).ToDictionary(x => x.ContentTypeKey); } diff --git a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs index 0cf3b5879e..f706e9ed59 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/MemberController.cs @@ -57,7 +57,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers private readonly IJsonSerializer _jsonSerializer; private readonly IShortStringHelper _shortStringHelper; private readonly IPasswordChanger _passwordChanger; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; /// /// Initializes a new instance of the class. @@ -91,7 +91,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers IBackOfficeSecurityAccessor backOfficeSecurityAccessor, IJsonSerializer jsonSerializer, IPasswordChanger passwordChanger, - IScopeProvider scopeProvider) + ICoreScopeProvider scopeProvider) : base(cultureDictionary, loggerFactory, shortStringHelper, eventMessages, localizedTextService, jsonSerializer) { _propertyEditors = propertyEditors; @@ -268,7 +268,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers // Create a scope here which will wrap all child data operations in a single transaction. // We'll complete this at the end of this method if everything succeeeds, else // all data operations will roll back. - using IScope scope = _scopeProvider.CreateScope(); + using ICoreScope scope = _scopeProvider.CreateCoreScope(); // Depending on the action we need to first do a create or update using the membership manager // this ensures that passwords are formatted correctly and also performs the validation on the provider itself. diff --git a/src/Umbraco.Web.BackOffice/DependencyInjection/UmbracoBuilder.BackOfficeIdentity.cs b/src/Umbraco.Web.BackOffice/DependencyInjection/UmbracoBuilder.BackOfficeIdentity.cs index 1545d25eab..ccd764d85b 100644 --- a/src/Umbraco.Web.BackOffice/DependencyInjection/UmbracoBuilder.BackOfficeIdentity.cs +++ b/src/Umbraco.Web.BackOffice/DependencyInjection/UmbracoBuilder.BackOfficeIdentity.cs @@ -35,7 +35,7 @@ namespace Umbraco.Extensions builder.BuildUmbracoBackOfficeIdentity() .AddDefaultTokenProviders() .AddUserStore, BackOfficeUserStore>(factory => new BackOfficeUserStore( - factory.GetRequiredService(), + factory.GetRequiredService(), factory.GetRequiredService(), factory.GetRequiredService(), factory.GetRequiredService(), diff --git a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs index 6b25370a8f..699b8561b2 100644 --- a/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs +++ b/src/Umbraco.Web.BackOffice/Filters/CheckIfUserTicketDataIsStaleAttribute.cs @@ -41,7 +41,7 @@ namespace Umbraco.Cms.Web.BackOffice.Filters private GlobalSettings _globalSettings; private readonly IBackOfficeSignInManager _backOfficeSignInManager; private readonly IBackOfficeAntiforgery _backOfficeAntiforgery; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly AppCaches _appCaches; public CheckIfUserTicketDataIsStaleFilter( @@ -53,7 +53,7 @@ namespace Umbraco.Cms.Web.BackOffice.Filters IOptionsSnapshot globalSettings, IBackOfficeSignInManager backOfficeSignInManager, IBackOfficeAntiforgery backOfficeAntiforgery, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, AppCaches appCaches) { _requestCache = requestCache; @@ -100,7 +100,7 @@ namespace Umbraco.Cms.Web.BackOffice.Filters private async Task CheckStaleData(ActionExecutingContext actionContext) { - using (var scope = _scopeProvider.CreateScope(autoComplete: true)) + using (var scope = _scopeProvider.CreateCoreScope(autoComplete: true)) { if (actionContext?.HttpContext.Request == null || actionContext.HttpContext.User?.Identity == null) { diff --git a/src/Umbraco.Web.Website/Controllers/UmbProfileController.cs b/src/Umbraco.Web.Website/Controllers/UmbProfileController.cs index 153a2bd1dc..a1e832f10c 100644 --- a/src/Umbraco.Web.Website/Controllers/UmbProfileController.cs +++ b/src/Umbraco.Web.Website/Controllers/UmbProfileController.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Web.Website.Controllers private readonly IMemberManager _memberManager; private readonly IMemberService _memberService; private readonly IMemberTypeService _memberTypeService; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; public UmbProfileController( IUmbracoContextAccessor umbracoContextAccessor, @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Web.Website.Controllers IMemberManager memberManager, IMemberService memberService, IMemberTypeService memberTypeService, - IScopeProvider scopeProvider) + ICoreScopeProvider scopeProvider) : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider) { _memberManager = memberManager; @@ -105,7 +105,7 @@ namespace Umbraco.Cms.Web.Website.Controllers private async Task UpdateMemberAsync(ProfileModel model, MemberIdentityUser currentMember) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); currentMember.Email = model.Email; currentMember.Name = model.Name; diff --git a/src/Umbraco.Web.Website/Controllers/UmbRegisterController.cs b/src/Umbraco.Web.Website/Controllers/UmbRegisterController.cs index 5881ea18f7..3b25c62a09 100644 --- a/src/Umbraco.Web.Website/Controllers/UmbRegisterController.cs +++ b/src/Umbraco.Web.Website/Controllers/UmbRegisterController.cs @@ -24,7 +24,7 @@ namespace Umbraco.Cms.Web.Website.Controllers private readonly IMemberManager _memberManager; private readonly IMemberService _memberService; private readonly IMemberSignInManager _memberSignInManager; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; public UmbRegisterController( IMemberManager memberManager, @@ -36,7 +36,7 @@ namespace Umbraco.Cms.Web.Website.Controllers IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider, IMemberSignInManager memberSignInManager, - IScopeProvider scopeProvider) + ICoreScopeProvider scopeProvider) : base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider) { _memberManager = memberManager; @@ -116,7 +116,7 @@ namespace Umbraco.Cms.Web.Website.Controllers /// Result of registration operation. private async Task RegisterMemberAsync(RegisterModel model, bool logMemberIn = true) { - using IScope scope = _scopeProvider.CreateScope(autoComplete: true); + using ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true); // U4-10762 Server error with "Register Member" snippet (Cannot save member with empty name) // If name field is empty, add the email address instead. diff --git a/tests/Umbraco.TestData/UmbracoTestDataController.cs b/tests/Umbraco.TestData/UmbracoTestDataController.cs index 9214d179b0..b3d909c937 100644 --- a/tests/Umbraco.TestData/UmbracoTestDataController.cs +++ b/tests/Umbraco.TestData/UmbracoTestDataController.cs @@ -32,7 +32,7 @@ namespace Umbraco.TestData private const string MediaPickerDataTypeName = "UmbracoTestDataContent.MediaPicker"; private const string TextDataTypeName = "UmbracoTestDataContent.Text"; private const string TestDataContentTypeAlias = "umbTestDataContent"; - private readonly IScopeProvider _scopeProvider; + private readonly ICoreScopeProvider _scopeProvider; private readonly PropertyEditorCollection _propertyEditors; private readonly IShortStringHelper _shortStringHelper; private readonly TestDataSettings _testDataSettings; @@ -44,7 +44,7 @@ namespace Umbraco.TestData AppCaches appCaches, IProfilingLogger profilingLogger, IPublishedUrlProvider publishedUrlProvider, - IScopeProvider scopeProvider, + ICoreScopeProvider scopeProvider, PropertyEditorCollection propertyEditors, IShortStringHelper shortStringHelper, IOptions testDataSettings) @@ -81,7 +81,7 @@ namespace Umbraco.TestData var faker = new Faker(locale); var company = faker.Company.CompanyName(); - using (IScope scope = _scopeProvider.CreateScope()) + using (ICoreScope scope = _scopeProvider.CreateCoreScope()) { var imageIds = CreateMediaTree(company, faker, count, depth).ToList(); var contentIds = CreateContentTree(company, faker, count, depth, imageIds, out var root).ToList(); diff --git a/tests/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj b/tests/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj index a83ec4d1ab..705f3333f9 100644 --- a/tests/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj +++ b/tests/Umbraco.Tests.Common/Umbraco.Tests.Common.csproj @@ -18,7 +18,6 @@ - diff --git a/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 32a58dd702..ee371873c0 100644 --- a/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -27,6 +27,7 @@ using Umbraco.Cms.Tests.Integration.DependencyInjection; using Umbraco.Cms.Tests.Integration.Extensions; using Umbraco.Cms.Web.Common.Hosting; using Umbraco.Extensions; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; namespace Umbraco.Cms.Tests.Integration.Testing { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/SectionServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/SectionServiceTests.cs index cd1437004b..691a6dfdbf 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/SectionServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/SectionServiceTests.cs @@ -11,7 +11,8 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; - +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services { /// diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs index 54392df0e4..48f340b084 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Umbraco. +// Copyright (c) Umbraco. // See LICENSE for more details. using System.Collections.Generic; @@ -22,6 +22,9 @@ using Umbraco.Cms.Tests.Common.Builders.Extensions; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services { /// diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs index 95b708f167..99e2d21158 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs @@ -85,6 +85,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine scopeProviderMock.Setup(x => x.CreateScope( It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Migrations/AdvancedMigrationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Migrations/AdvancedMigrationTests.cs index 0a9e075f87..df4670537b 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Migrations/AdvancedMigrationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Migrations/AdvancedMigrationTests.cs @@ -24,6 +24,9 @@ using Umbraco.Cms.Tests.Common.TestHelpers; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Migrations { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs index 3feac1ce38..70a9b2969f 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs @@ -22,6 +22,9 @@ using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.Importing; using Umbraco.Extensions; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Packaging { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs index d146729e48..f26dd22194 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs @@ -8,10 +8,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NPoco; using NUnit.Framework; -using Serilog; using Umbraco.Cms.Core; using Umbraco.Cms.Core.DistributedLocking.Exceptions; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence.Dtos; using Umbraco.Cms.Persistence.Sqlite.Interceptors; using Umbraco.Cms.Tests.Common.Testing; @@ -438,7 +436,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using var scope = ScopeProvider.CreateScope(); - _ = (scope as Scope)?.Database; // Begin transaction + _ = scope.Database; // Begin transaction Interlocked.Increment(ref counter); gate.Wait(); @@ -461,7 +459,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { using var scope = ScopeProvider.CreateScope(); - _ = (scope as Scope)?.Database; // Begin transaction + _ = scope.Database; // Begin transaction Interlocked.Increment(ref counter); gate.Wait(); Thread.Sleep(100); // Let other transaction obtain write lock first. diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoBulkInsertTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoBulkInsertTests.cs index 10b0a06032..319b9aa973 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoBulkInsertTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoBulkInsertTests.cs @@ -17,6 +17,9 @@ using Umbraco.Cms.Tests.Integration.Implementations; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPocoTests { // FIXME: npoco - is this still appropriate? diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoFetchTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoFetchTests.cs index 4954d7a371..4438c541d2 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoFetchTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/NPocoTests/NPocoFetchTests.cs @@ -12,6 +12,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.NPocoTests { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/AuditRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/AuditRepositoryTest.cs index 4951146147..12caa0d8dd 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/AuditRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/AuditRepositoryTest.cs @@ -16,6 +16,9 @@ using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/CacheInstructionRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/CacheInstructionRepositoryTest.cs index f39b4311b2..7f0449db93 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/CacheInstructionRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/CacheInstructionRepositoryTest.cs @@ -17,6 +17,9 @@ using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs index 38882c1638..e79227a44d 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs @@ -25,6 +25,9 @@ using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; using Content = Umbraco.Cms.Core.Models.Content; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs index 8cb7686982..f4a3037436 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs @@ -16,6 +16,9 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs index fc3caa6acf..21d92f2b93 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs @@ -14,6 +14,9 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs index 55409fe6d7..3960fc8107 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DocumentRepositoryTest.cs @@ -32,6 +32,9 @@ using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DomainRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DomainRepositoryTest.cs index 4928354d97..a842a1ac61 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DomainRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DomainRepositoryTest.cs @@ -16,6 +16,8 @@ using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/EntityRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/EntityRepositoryTest.cs index a70355c887..7596841a6c 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/EntityRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/EntityRepositoryTest.cs @@ -17,6 +17,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs index 4f6934a481..b8776e4973 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/KeyValueRepositoryTests.cs @@ -21,10 +21,10 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos [Test] public void CanSetAndGet() { - IScopeProvider provider = ScopeProvider; + ICoreScopeProvider provider = ScopeProvider; // Insert new key/value - using (IScope scope = provider.CreateScope()) + using (ICoreScope scope = provider.CreateCoreScope()) { var keyValue = new KeyValue { @@ -38,7 +38,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } // Retrieve key/value - using (IScope scope = provider.CreateScope()) + using (ICoreScope scope = provider.CreateCoreScope()) { IKeyValueRepository repo = CreateRepository(provider); IKeyValue keyValue = repo.Get("foo"); @@ -48,7 +48,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } // Update value - using (IScope scope = provider.CreateScope()) + using (ICoreScope scope = provider.CreateCoreScope()) { IKeyValueRepository repo = CreateRepository(provider); IKeyValue keyValue = repo.Get("foo"); @@ -59,7 +59,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } // Retrieve key/value again - using (IScope scope = provider.CreateScope()) + using (ICoreScope scope = provider.CreateCoreScope()) { IKeyValueRepository repo = CreateRepository(provider); IKeyValue keyValue = repo.Get("foo"); @@ -69,6 +69,6 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos } } - private IKeyValueRepository CreateRepository(IScopeProvider provider) => new KeyValueRepository((IScopeAccessor)provider, LoggerFactory.CreateLogger()); + private IKeyValueRepository CreateRepository(ICoreScopeProvider provider) => new KeyValueRepository((IScopeAccessor)provider, LoggerFactory.CreateLogger()); } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs index 3c157d9c5a..03928ccecb 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs @@ -18,6 +18,8 @@ using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MacroRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MacroRepositoryTest.cs index bb1e04fe91..834800e675 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MacroRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MacroRepositoryTest.cs @@ -16,6 +16,9 @@ using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs index 1acba24035..7e4a1462ee 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaRepositoryTest.cs @@ -29,6 +29,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaTypeRepositoryTest.cs index 51a71c30e1..52198c7188 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MediaTypeRepositoryTest.cs @@ -18,6 +18,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs index d5fb7d3edc..20ccce4d72 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberRepositoryTest.cs @@ -35,6 +35,9 @@ using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberTypeRepositoryTest.cs index 33209abc6a..4d378615b0 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/MemberTypeRepositoryTest.cs @@ -20,6 +20,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/NotificationsRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/NotificationsRepositoryTest.cs index f7bfbb989e..bf33238178 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/NotificationsRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/NotificationsRepositoryTest.cs @@ -18,6 +18,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PartialViewRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PartialViewRepositoryTests.cs index 4c6204ee4e..3596c0c30f 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PartialViewRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PartialViewRepositoryTests.cs @@ -18,6 +18,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs index 283c8e57aa..36b394d5f4 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/PublicAccessRepositoryTest.cs @@ -17,6 +17,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Content = Umbraco.Cms.Core.Models.Content; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RedirectUrlRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RedirectUrlRepositoryTests.cs index af75016d9a..aa8823db28 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RedirectUrlRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RedirectUrlRepositoryTests.cs @@ -16,6 +16,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs index f9d0b5291a..72766a97f5 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs @@ -21,6 +21,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationTypeRepositoryTest.cs index 1f8ba39057..ba1fb3f7d4 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationTypeRepositoryTest.cs @@ -24,15 +24,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos [SetUp] public void SetUp() => CreateTestData(); - private RelationTypeRepository CreateRepository(IScopeProvider provider) => + private RelationTypeRepository CreateRepository(ICoreScopeProvider provider) => new RelationTypeRepository((IScopeAccessor)provider, AppCaches.Disabled, LoggerFactory.CreateLogger()); [Test] public void Can_Perform_Add_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -51,8 +51,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Update_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -76,8 +76,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Delete_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -96,8 +96,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Get_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -120,8 +120,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_GetAll_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -140,8 +140,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_GetAll_With_Params_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -160,8 +160,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Exists_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -179,8 +179,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Count_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -197,8 +197,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_GetByQuery_On_RelationTypeRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { RelationTypeRepository repository = CreateRepository(provider); @@ -221,8 +221,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos var relateContentType = new RelationType("Relate ContentType on Copy", "relateContentTypeOnCopy", true, Constants.ObjectTypes.DocumentType, Constants.ObjectTypes.DocumentType, false); var relateContentMedia = new RelationType("Relate Content to Media", "relateContentToMedia", true, Constants.ObjectTypes.Document, Constants.ObjectTypes.Media, true); - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { var repository = new RelationTypeRepository((IScopeAccessor)provider, AppCaches.Disabled, LoggerFactory.CreateLogger()); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ScriptRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ScriptRepositoryTest.cs index 4721af14e1..939e774a01 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ScriptRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ScriptRepositoryTest.cs @@ -20,6 +20,9 @@ using Umbraco.Cms.Tests.Common.TestHelpers; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ServerRegistrationRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ServerRegistrationRepositoryTest.cs index bc7058ed58..c7c01bde6f 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ServerRegistrationRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ServerRegistrationRepositoryTest.cs @@ -16,6 +16,9 @@ using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TagRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TagRepositoryTest.cs index 8dc0a2ed81..2432f754f4 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TagRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TagRepositoryTest.cs @@ -16,6 +16,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs index 7b0b8b9e21..8d81d9c4a8 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs @@ -30,6 +30,9 @@ using Umbraco.Cms.Tests.Integration.Implementations; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserGroupRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserGroupRepositoryTest.cs index 367d4f770e..a24f7eadb6 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserGroupRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserGroupRepositoryTest.cs @@ -15,6 +15,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositories { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserRepositoryTest.cs index 52af0ac615..1cd1252d67 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/UserRepositoryTest.cs @@ -44,7 +44,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos private IMediaRepository MediaRepository => GetRequiredService(); - private UserRepository CreateRepository(IScopeProvider provider) + private UserRepository CreateRepository(ICoreScopeProvider provider) { var accessor = (IScopeAccessor)provider; Mock mockRuntimeState = CreateMockRuntimeState(RuntimeLevel.Run); @@ -60,7 +60,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos return mockRuntimeState; } - private UserGroupRepository CreateUserGroupRepository(IScopeProvider provider) + private UserGroupRepository CreateUserGroupRepository(ICoreScopeProvider provider) { var accessor = (IScopeAccessor)provider; return new UserGroupRepository(accessor, AppCaches.Disabled, LoggerFactory.CreateLogger(), LoggerFactory, ShortStringHelper); @@ -70,8 +70,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Add_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -89,8 +89,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Multiple_Adds_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -112,8 +112,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Verify_Fresh_Entity_Is_Not_Dirty() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -133,8 +133,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Delete_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -162,8 +162,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Get_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); UserGroupRepository userGroupRepository = CreateUserGroupRepository(provider); @@ -185,8 +185,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_GetByQuery_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -205,8 +205,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_GetAll_By_Param_Ids_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -226,8 +226,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_GetAll_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -247,8 +247,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Exists_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -266,8 +266,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Perform_Count_On_UserRepository() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -285,8 +285,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos [Test] public void Can_Get_Paged_Results_By_Query_And_Filter_And_Groups() { - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -323,8 +323,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos [Test] public void Can_Get_Paged_Results_With_Filter_And_Groups() { - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); @@ -362,8 +362,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Can_Invalidate_SecurityStamp_On_Username_Change() { // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope()) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope()) { UserRepository repository = CreateRepository(provider); UserGroupRepository userGroupRepository = CreateUserGroupRepository(provider); @@ -391,15 +391,15 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos public void Validate_Login_Session() { // Arrange - IScopeProvider provider = ScopeProvider; + ICoreScopeProvider provider = ScopeProvider; User user = UserBuilder.CreateUser(); - using (IScope scope = provider.CreateScope(autoComplete: true)) + using (ICoreScope scope = provider.CreateCoreScope(autoComplete: true)) { UserRepository repository = CreateRepository(provider); repository.Save(user); } - using (IScope scope = provider.CreateScope(autoComplete: true)) + using (ICoreScope scope = provider.CreateCoreScope(autoComplete: true)) { UserRepository repository = CreateRepository(provider); Guid sessionId = repository.CreateLoginSession(user.Id, "1.2.3.4"); @@ -426,8 +426,8 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos MediaType mt = MediaTypeBuilder.CreateSimpleMediaType("testmedia", "TestMedia"); // Arrange - IScopeProvider provider = ScopeProvider; - using (IScope scope = provider.CreateScope(autoComplete: true)) + ICoreScopeProvider provider = ScopeProvider; + using (ICoreScope scope = provider.CreateCoreScope(autoComplete: true)) { UserRepository userRepository = CreateRepository(provider); UserGroupRepository userGroupRepository = CreateUserGroupRepository(provider); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/UnitOfWorkTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/UnitOfWorkTests.cs index 4eb670c4a8..f6ee9e01b0 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/UnitOfWorkTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/UnitOfWorkTests.cs @@ -11,6 +11,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeFileSystemsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeFileSystemsTests.cs index 7ea8e65eda..3e4268e496 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeFileSystemsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeFileSystemsTests.cs @@ -12,6 +12,7 @@ using NUnit.Framework; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -19,6 +20,9 @@ using Umbraco.Extensions; using Constants = Umbraco.Cms.Core.Constants; using FileSystems = Umbraco.Cms.Core.IO.FileSystems; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs index c4f2db58fe..cfd9e49583 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopeTests.cs @@ -14,10 +14,12 @@ using NUnit.Framework; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Persistence; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs index c228e07178..4cd8b3ff2f 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs @@ -16,11 +16,15 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.Implement; using Umbraco.Cms.Core.Sync; using Umbraco.Cms.Infrastructure.PublishedCache; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Infrastructure.Sync; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/SupressNotificationsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/SupressNotificationsTests.cs index c5cff66d0a..3bc091de70 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/SupressNotificationsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/SupressNotificationsTests.cs @@ -13,6 +13,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/CacheInstructionServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/CacheInstructionServiceTests.cs index 80005f8058..4024bdcf3c 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/CacheInstructionServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/CacheInstructionServiceTests.cs @@ -19,6 +19,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePerformanceTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePerformanceTest.cs index 0c514007f1..b068ec4ac8 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePerformanceTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePerformanceTest.cs @@ -20,6 +20,9 @@ using Umbraco.Cms.Tests.Common.TestHelpers.Stubs; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs index c082d93946..2412fca3e0 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs @@ -17,6 +17,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs index 3eaa89158d..f3bc25c9c8 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs @@ -30,6 +30,9 @@ using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { /// diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs index bfda211d74..92f9d73a89 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs @@ -21,6 +21,9 @@ using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping; using Umbraco.Extensions; using Language = Umbraco.Cms.Core.Models.Language; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs index 97a5698ef0..23bcd6ded2 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentVersionCleanupServiceTest.cs @@ -9,6 +9,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ExternalLoginServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ExternalLoginServiceTests.cs index 971379d6a9..f322ea01ca 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ExternalLoginServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ExternalLoginServiceTests.cs @@ -12,6 +12,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] @@ -33,7 +36,7 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services DateTime latest = DateTime.Now.AddDays(-1); DateTime oldest = DateTime.Now.AddDays(-10); - using (global::Umbraco.Cms.Core.Scoping.IScope scope = ScopeProvider.CreateScope()) + using (IScope scope = ScopeProvider.CreateScope()) { // insert duplicates manuall ScopeAccessor.AmbientScope.Database.Insert(new ExternalLoginDto diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LocalizationServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LocalizationServiceTests.cs index aca0ee4183..370c0ffd95 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LocalizationServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LocalizationServiceTests.cs @@ -16,6 +16,9 @@ using Umbraco.Cms.Tests.Common.Builders.Extensions; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { /// diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MacroServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MacroServiceTests.cs index 6601fcfbc2..bd233e5243 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MacroServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MacroServiceTests.cs @@ -18,6 +18,9 @@ using Umbraco.Cms.Tests.Common.Builders.Extensions; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaServiceTests.cs index 16b9430ff7..115a37e7af 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaServiceTests.cs @@ -17,6 +17,9 @@ using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs index c2316b7752..86ec5769b3 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MemberServiceTests.cs @@ -27,6 +27,9 @@ using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { [TestFixture] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/RedirectUrlServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/RedirectUrlServiceTests.cs index a0abfd70ee..8086018d0d 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/RedirectUrlServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/RedirectUrlServiceTests.cs @@ -14,6 +14,8 @@ using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ThreadSafetyServiceTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ThreadSafetyServiceTest.cs index 21d15c13a6..88adef3824 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ThreadSafetyServiceTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ThreadSafetyServiceTest.cs @@ -13,12 +13,16 @@ using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.Implement; using Umbraco.Cms.Infrastructure.Persistence; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Extensions; using Constants = Umbraco.Cms.Core.Constants; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; + namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { // these tests tend to fail from time to time esp. on VSTS diff --git a/tests/Umbraco.Tests.UnitTests/TestHelpers/PublishedSnapshotServiceTestBase.cs b/tests/Umbraco.Tests.UnitTests/TestHelpers/PublishedSnapshotServiceTestBase.cs index cfe3830970..4cf6ffdc9e 100644 --- a/tests/Umbraco.Tests.UnitTests/TestHelpers/PublishedSnapshotServiceTestBase.cs +++ b/tests/Umbraco.Tests.UnitTests/TestHelpers/PublishedSnapshotServiceTestBase.cs @@ -230,6 +230,7 @@ namespace Umbraco.Cms.Tests.UnitTests.TestHelpers .Setup(x => x.CreateScope( It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DefaultCachePolicyTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DefaultCachePolicyTests.cs index 85e1c9a221..f14af8cc19 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DefaultCachePolicyTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DefaultCachePolicyTests.cs @@ -7,7 +7,6 @@ using Moq; using NUnit.Framework; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache @@ -20,8 +19,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache get { var accessor = new Mock(); - var scope = new Mock(); - scope.Setup(x => x.RepositoryCacheMode).Returns(RepositoryCacheMode.Default); + var scope = new Mock(); + scope.Setup(x => x.RepositoryCacheMode).Returns(Cms.Core.Scoping.RepositoryCacheMode.Default); accessor.Setup(x => x.AmbientScope).Returns(scope.Object); return accessor.Object; } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/FullDataSetCachePolicyTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/FullDataSetCachePolicyTests.cs index 578e133a16..284454ea25 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/FullDataSetCachePolicyTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/FullDataSetCachePolicyTests.cs @@ -10,7 +10,6 @@ using NUnit.Framework; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Collections; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache @@ -23,8 +22,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache get { var accessor = new Mock(); - var scope = new Mock(); - scope.Setup(x => x.RepositoryCacheMode).Returns(RepositoryCacheMode.Default); + var scope = new Mock(); + scope.Setup(x => x.RepositoryCacheMode).Returns(Cms.Core.Scoping.RepositoryCacheMode.Default); accessor.Setup(x => x.AmbientScope).Returns(scope.Object); return accessor.Object; } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/SingleItemsOnlyCachePolicyTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/SingleItemsOnlyCachePolicyTests.cs index 20c6d173c2..e38cab93e5 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/SingleItemsOnlyCachePolicyTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/SingleItemsOnlyCachePolicyTests.cs @@ -9,6 +9,7 @@ using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Scoping; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache { @@ -20,7 +21,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Cache get { var accessor = new Mock(); - var scope = new Mock(); + var scope = new Mock(); scope.Setup(x => x.RepositoryCacheMode).Returns(RepositoryCacheMode.Default); accessor.Setup(x => x.AmbientScope).Returns(scope.Object); return accessor.Object; diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs index 17ea228cd1..7593e52511 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs @@ -71,14 +71,14 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Components Mock.Of(), Options.Create(new ContentSettings())); IEventAggregator eventAggregator = Mock.Of(); - var scopeProvider = new ScopeProvider(Mock.Of(),f , fs, new TestOptionsMonitor(coreDebug), loggerFactory, NoAppCache.Instance, eventAggregator); + var scopeProvider = new ScopeProvider(Mock.Of(),f , fs, new TestOptionsMonitor(coreDebug), mediaFileManager, loggerFactory, NoAppCache.Instance, eventAggregator); mock.Setup(x => x.GetService(typeof(ILogger))).Returns(logger); mock.Setup(x => x.GetService(typeof(ILogger))).Returns(loggerFactory.CreateLogger); mock.Setup(x => x.GetService(typeof(ILoggerFactory))).Returns(loggerFactory); mock.Setup(x => x.GetService(typeof(IProfilingLogger))).Returns(new ProfilingLogger(loggerFactory.CreateLogger(), Mock.Of())); mock.Setup(x => x.GetService(typeof(IUmbracoDatabaseFactory))).Returns(f); - mock.Setup(x => x.GetService(typeof(IScopeProvider))).Returns(scopeProvider); + mock.Setup(x => x.GetService(typeof(ICoreScopeProvider))).Returns(scopeProvider); setup?.Invoke(mock); return mock.Object; diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/ScopedNotificationPublisherTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/ScopedNotificationPublisherTests.cs index 031a9767c1..6ddc506753 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/ScopedNotificationPublisherTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/ScopedNotificationPublisherTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Scoping var notificationPublisherMock = new Mock(); ScopeProvider scopeProvider = GetScopeProvider(out var eventAggregatorMock); - using (IScope scope = scopeProvider.CreateScope(notificationPublisher: notificationPublisherMock.Object)) + using (ICoreScope scope = scopeProvider.CreateScope(notificationPublisher: notificationPublisherMock.Object)) { scope.Notifications.Publish(Mock.Of()); scope.Notifications.PublishCancelable(Mock.Of()); @@ -41,7 +41,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Scoping notificationPublisherMock.Verify(x => x.PublishCancelable(It.IsAny()), Times.Once); // Ensure that the custom scope provider is till used in inner scope. - using (IScope innerScope = scopeProvider.CreateScope()) + using (ICoreScope innerScope = scopeProvider.CreateScope()) { innerScope.Notifications.Publish(Mock.Of()); innerScope.Notifications.PublishCancelable(Mock.Of()); @@ -97,6 +97,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Scoping Mock.Of(), fileSystems, new TestOptionsMonitor(new CoreDebugSettings()), + mediaFileManager, loggerFactory, Mock.Of(), eventAggregatorMock.Object diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/LogScrubberTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/LogScrubberTests.cs index fc61f90150..eae96be4ee 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/LogScrubberTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/LogScrubberTests.cs @@ -75,9 +75,9 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices mockMainDom.SetupGet(x => x.IsMainDom).Returns(isMainDom); var mockScope = new Mock(); - var mockScopeProvider = new Mock(); + var mockScopeProvider = new Mock(); mockScopeProvider - .Setup(x => x.CreateScope(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(x => x.CreateCoreScope(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(mockScope.Object); var mockLogger = new Mock>(); var mockProfilingLogger = new Mock(); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs index 1379e99b99..12e5c22fd8 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/HostedServices/ScheduledPublishingTests.cs @@ -111,9 +111,9 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.HostedServices var mockServerMessenger = new Mock(); - var mockScopeProvider = new Mock(); + var mockScopeProvider = new Mock(); mockScopeProvider - .Setup(x => x.CreateScope(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(x => x.CreateCoreScope(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(Mock.Of()); return new ScheduledPublishing( diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs index f707464443..9c8f9da75d 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs @@ -29,6 +29,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Mapping scopeMock.Setup(x => x.CreateScope( It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs index b9f45afd67..8fbcf05ddc 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationPlanTests.cs @@ -24,6 +24,7 @@ using Umbraco.Cms.Persistence.SqlServer.Services; using Umbraco.Cms.Tests.Common.TestHelpers; using Umbraco.Cms.Tests.UnitTests.TestHelpers; using Umbraco.Extensions; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations { @@ -36,7 +37,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations NullLoggerFactory loggerFactory = NullLoggerFactory.Instance; var database = new TestDatabase(); - IDatabaseScope scope = Mock.Of(x => x.Notifications == Mock.Of()); + IScope scope = Mock.Of(x => x.Notifications == Mock.Of()); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs index 2f2e36221c..7f5b284023 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs @@ -11,10 +11,10 @@ using Moq; using NUnit.Framework; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Persistence.Querying; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Scoping; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations { @@ -23,13 +23,14 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations { public class TestScopeProvider : IScopeProvider, IScopeAccessor { - private readonly IDatabaseScope _scope; + private readonly IScope _scope; - public TestScopeProvider(IDatabaseScope scope) => _scope = scope; + public TestScopeProvider(IScope scope) => _scope = scope; public IScope CreateScope( IsolationLevel isolationLevel = IsolationLevel.Unspecified, - RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + Cms.Core.Scoping.RepositoryCacheMode repositoryCacheMode = Cms.Core.Scoping.RepositoryCacheMode.Unspecified, + IEventDispatcher eventDispatcher = null, IScopedNotificationPublisher notificationPublisher = null, bool? scopeFileSystems = null, bool callContext = false, @@ -37,7 +38,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations public IScope CreateDetachedScope( IsolationLevel isolationLevel = IsolationLevel.Unspecified, - RepositoryCacheMode repositoryCacheMode = RepositoryCacheMode.Unspecified, + Cms.Core.Scoping.RepositoryCacheMode repositoryCacheMode = Cms.Core.Scoping.RepositoryCacheMode.Unspecified, + IEventDispatcher eventDispatcher = null, IScopedNotificationPublisher notificationPublisher = null, bool? scopeFileSystems = null) => throw new NotImplementedException(); @@ -45,7 +47,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations public IScope DetachScope() => throw new NotImplementedException(); - public IScopeContext Context { get; set; } + public Cms.Core.Scoping.IScopeContext Context { get; set; } public IQuery CreateQuery() => SqlContext.Query(); public ISqlContext SqlContext { get; set; } @@ -57,7 +59,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations } public IEnumerable ScopeInfos => throw new NotImplementedException(); #endif - public IDatabaseScope AmbientScope => _scope; + public IScope AmbientScope => _scope; } private class TestPlan : MigrationPlan diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs index 37cb93116b..05d9cf6cbc 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs @@ -21,6 +21,7 @@ using Umbraco.Cms.Infrastructure.Persistence.SqlSyntax; using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Persistence.SqlServer.Services; using Umbraco.Cms.Tests.Common.TestHelpers; +using IScope = Umbraco.Cms.Infrastructure.Scoping.IScope; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations { @@ -28,7 +29,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations public class PostMigrationTests { private static readonly ILoggerFactory s_loggerFactory = NullLoggerFactory.Instance; - private IMigrationPlanExecutor GetMigrationPlanExecutor(IScopeProvider scopeProvider, IScopeAccessor scopeAccessor,IMigrationBuilder builder) + private IMigrationPlanExecutor GetMigrationPlanExecutor(ICoreScopeProvider scopeProvider, IScopeAccessor scopeAccessor,IMigrationBuilder builder) => new MigrationPlanExecutor(scopeProvider, scopeAccessor, s_loggerFactory, builder); [Test] @@ -51,7 +52,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations }); var database = new TestDatabase(); - IDatabaseScope scope = Mock.Of(x => x.Notifications == Mock.Of()); + IScope scope = Mock.Of(x => x.Notifications == Mock.Of()); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); @@ -100,7 +101,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations }); var database = new TestDatabase(); - IDatabaseScope scope = Mock.Of(x => x.Notifications == Mock.Of()); + IScope scope = Mock.Of(x => x.Notifications == Mock.Of()); Mock.Get(scope) .Setup(x => x.Database) .Returns(database); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Scoping/ScopeUnitTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Scoping/ScopeUnitTests.cs index ac2cd27f41..f429f584e5 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Scoping/ScopeUnitTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Scoping/ScopeUnitTests.cs @@ -75,6 +75,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Scoping databaseFactory.Object, fileSystems, new TestOptionsMonitor(new CoreDebugSettings()), + mediaFileManager, loggerFactory, Mock.Of(), Mock.Of()); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberUserStoreTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberUserStoreTests.cs index a7ad27f1a6..14261e34fb 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberUserStoreTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Security/MemberUserStoreTests.cs @@ -29,7 +29,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Security var mockScope = new Mock(); var mockScopeProvider = new Mock(); mockScopeProvider - .Setup(x => x.CreateScope(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(x => x.CreateScope(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(mockScope.Object); return new MemberUserStore( diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.PublishedCache.NuCache/SnapDictionaryTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.PublishedCache.NuCache/SnapDictionaryTests.cs index fdb29f88e6..a0d3c9b9eb 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.PublishedCache.NuCache/SnapDictionaryTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.PublishedCache.NuCache/SnapDictionaryTests.cs @@ -731,7 +731,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache Assert.AreEqual(0, d.CreateSnapshot().Gen); // no scope context: writers nest, last one to be disposed commits - IScopeProvider scopeProvider = GetScopeProvider(); + ICoreScopeProvider scopeProvider = GetScopeProvider(); using (IDisposable w1 = d.GetScopedWriteLock(scopeProvider)) { @@ -770,7 +770,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache // scope context: writers enlist var scopeContext = new ScopeContext(); - IScopeProvider scopeProvider = GetScopeProvider(scopeContext); + ICoreScopeProvider scopeProvider = GetScopeProvider(scopeContext); using (IDisposable w1 = d.GetScopedWriteLock(scopeProvider)) { @@ -795,8 +795,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache Assert.AreEqual(0, d.CreateSnapshot().Gen); var scopeContext = new ScopeContext(); - IScopeProvider scopeProvider1 = GetScopeProvider(); - IScopeProvider scopeProvider2 = GetScopeProvider(scopeContext); + ICoreScopeProvider scopeProvider1 = GetScopeProvider(); + ICoreScopeProvider scopeProvider2 = GetScopeProvider(scopeContext); using (IDisposable w1 = d.GetScopedWriteLock(scopeProvider1)) { @@ -848,7 +848,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache Assert.IsFalse(d.Test.NextGen); Assert.AreEqual("uno", s2.Get(1)); - IScopeProvider scopeProvider = GetScopeProvider(); + ICoreScopeProvider scopeProvider = GetScopeProvider(); using (d.GetScopedWriteLock(scopeProvider)) { // gen 3 @@ -892,7 +892,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache Assert.AreEqual(2, s2.Gen); Assert.AreEqual("uno", s2.Get(1)); - IScopeProvider scopeProvider = GetScopeProvider(); + ICoreScopeProvider scopeProvider = GetScopeProvider(); using (d.GetScopedWriteLock(scopeProvider)) { // creating a snapshot in a write-lock does NOT return the "current" content @@ -931,7 +931,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache Assert.AreEqual("uno", s2.Get(1)); var scopeContext = new ScopeContext(); - IScopeProvider scopeProvider = GetScopeProvider(scopeContext); + ICoreScopeProvider scopeProvider = GetScopeProvider(scopeContext); using (d.GetScopedWriteLock(scopeProvider)) { // creating a snapshot in a write-lock does NOT return the "current" content @@ -980,7 +980,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache Assert.IsFalse(t.NextGen); var scopeContext = new ScopeContext(); - IScopeProvider scopeProvider = GetScopeProvider(scopeContext); + ICoreScopeProvider scopeProvider = GetScopeProvider(scopeContext); using (d.GetScopedWriteLock(scopeProvider)) { // creating a snapshot in a write-lock does NOT return the "current" content @@ -1087,7 +1087,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache Assert.AreEqual(1, d.Test.GenObj.Gen); var scopeContext = new ScopeContext(); - IScopeProvider scopeProvider = GetScopeProvider(scopeContext); + ICoreScopeProvider scopeProvider = GetScopeProvider(scopeContext); // scopeProvider.Context == scopeContext -> writer is scoped // writer is scope contextual and scoped @@ -1138,9 +1138,9 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.PublishedCache.NuCache Assert.IsFalse(d.Test.NextGen); } - private IScopeProvider GetScopeProvider(ScopeContext scopeContext = null) + private ICoreScopeProvider GetScopeProvider(ScopeContext scopeContext = null) { - IScopeProvider scopeProvider = Mock.Of(); + ICoreScopeProvider scopeProvider = Mock.Of(); Mock.Get(scopeProvider) .Setup(x => x.Context).Returns(scopeContext); return scopeProvider; diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs index 41e0434ebc..7d7de45950 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs @@ -520,13 +520,14 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.BackOffice.Controllers new Mock().Object, new Mock>().Object) }); - var scopeProvider = Mock.Of(x => x.CreateScope( + var scopeProvider = Mock.Of(x => x.CreateCoreScope( It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny()) == Mock.Of()); + It.IsAny()) == Mock.Of()); _mapper = new UmbracoMapper(map, scopeProvider);