diff --git a/src/Umbraco.Core/Events/IScopedNotificationPublisher.cs b/src/Umbraco.Core/Events/IScopedNotificationPublisher.cs new file mode 100644 index 0000000000..e6c8a06647 --- /dev/null +++ b/src/Umbraco.Core/Events/IScopedNotificationPublisher.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; + +namespace Umbraco.Cms.Core.Events +{ + public interface IScopedNotificationPublisher + { + /// + /// Publishes a cancelable notification to the notification subscribers + /// + /// + /// True if the notification was cancelled by a subscriber, false otherwise + bool PublishCancelable(ICancelableNotification notification); + + /// + /// Publishes a cancelable notification to the notification subscribers + /// + /// + /// True if the notification was cancelled by a subscriber, false otherwise + Task PublishCancelableAsync(ICancelableNotification notification); + + /// + /// Publishes a notification to the notification subscribers + /// + /// + /// The notification is published upon successful completion of the current scope, i.e. when things have been saved/published/deleted etc. + void Publish(INotification notification); + + /// + /// Invokes publishing of all pending notifications within the current scope + /// + /// + void ScopeExit(bool completed); + } +} diff --git a/src/Umbraco.Core/Events/ScopedNotificationPublisher.cs b/src/Umbraco.Core/Events/ScopedNotificationPublisher.cs new file mode 100644 index 0000000000..dfaca55663 --- /dev/null +++ b/src/Umbraco.Core/Events/ScopedNotificationPublisher.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Umbraco.Cms.Core.Events +{ + public class ScopedNotificationPublisher : IScopedNotificationPublisher + { + private readonly IEventAggregator _eventAggregator; + private readonly List _notificationOnScopeCompleted; + + public ScopedNotificationPublisher(IEventAggregator eventAggregator) + { + _eventAggregator = eventAggregator; + _notificationOnScopeCompleted = new List(); + } + + public bool PublishCancelable(ICancelableNotification notification) + { + if (notification == null) + { + throw new ArgumentNullException(nameof(notification)); + } + + _eventAggregator.Publish(notification); + return notification.Cancel; + } + + public async Task PublishCancelableAsync(ICancelableNotification notification) + { + if (notification == null) + { + throw new ArgumentNullException(nameof(notification)); + } + + await _eventAggregator.PublishAsync(notification); + return notification.Cancel; + } + + public void Publish(INotification notification) + { + if (notification == null) + { + throw new ArgumentNullException(nameof(notification)); + } + + _notificationOnScopeCompleted.Add(notification); + } + + public void ScopeExit(bool completed) + { + try + { + if (completed) + { + foreach (var notification in _notificationOnScopeCompleted) + { + _eventAggregator.Publish(notification); + } + } + } + finally + { + _notificationOnScopeCompleted.Clear(); + } + } + } +} diff --git a/src/Umbraco.Infrastructure/Scoping/IScope.cs b/src/Umbraco.Infrastructure/Scoping/IScope.cs index 7a6a62a6c7..ab1d905b44 100644 --- a/src/Umbraco.Infrastructure/Scoping/IScope.cs +++ b/src/Umbraco.Infrastructure/Scoping/IScope.cs @@ -1,4 +1,4 @@ -using System; +using System; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Infrastructure.Persistence; @@ -30,6 +30,11 @@ namespace Umbraco.Cms.Core.Scoping /// IEventDispatcher Events { get; } + /// + /// Gets the scope notification publisher + /// + IScopedNotificationPublisher Notifications { get; } + /// /// Gets the repositories cache mode. /// diff --git a/src/Umbraco.Infrastructure/Scoping/Scope.cs b/src/Umbraco.Infrastructure/Scoping/Scope.cs index 7d50f5e55a..a374f8726b 100644 --- a/src/Umbraco.Infrastructure/Scoping/Scope.cs +++ b/src/Umbraco.Infrastructure/Scoping/Scope.cs @@ -19,6 +19,7 @@ namespace Umbraco.Cms.Core.Scoping private readonly ScopeProvider _scopeProvider; private readonly CoreDebugSettings _coreDebugSettings; private readonly IMediaFileSystem _mediaFileSystem; + private readonly IEventAggregator _eventAggregator; private readonly ILogger _logger; private readonly IsolationLevel _isolationLevel; @@ -35,12 +36,15 @@ namespace Umbraco.Cms.Core.Scoping private EventMessages _messages; private ICompletable _fscope; private IEventDispatcher _eventDispatcher; + // eventually this may need to be injectable - for now we'll create it explicitly and let future needs determine if it should be injectable + private IScopedNotificationPublisher _notificationPublisher; // initializes a new scope private Scope( ScopeProvider scopeProvider, CoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, + IEventAggregator eventAggregator, ILogger logger, FileSystems fileSystems, Scope parent, @@ -56,6 +60,7 @@ namespace Umbraco.Cms.Core.Scoping _scopeProvider = scopeProvider; _coreDebugSettings = coreDebugSettings; _mediaFileSystem = mediaFileSystem; + _eventAggregator = eventAggregator; _logger = logger; Context = scopeContext; @@ -69,6 +74,7 @@ namespace Umbraco.Cms.Core.Scoping Detachable = detachable; + #if DEBUG_SCOPES _scopeProvider.RegisterScope(this); Console.WriteLine("create " + InstanceId.ToString("N").Substring(0, 8)); @@ -124,6 +130,7 @@ namespace Umbraco.Cms.Core.Scoping ScopeProvider scopeProvider, CoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, + IEventAggregator eventAggregator, ILogger logger, FileSystems fileSystems, bool detachable, @@ -134,7 +141,7 @@ namespace Umbraco.Cms.Core.Scoping bool? scopeFileSystems = null, bool callContext = false, bool autoComplete = false) - : this(scopeProvider, coreDebugSettings, mediaFileSystem, logger, fileSystems, null, scopeContext, detachable, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete) + : this(scopeProvider, coreDebugSettings, mediaFileSystem, eventAggregator, logger, fileSystems, null, scopeContext, detachable, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete) { } // initializes a new scope in a nested scopes chain, with its parent @@ -142,6 +149,7 @@ namespace Umbraco.Cms.Core.Scoping ScopeProvider scopeProvider, CoreDebugSettings coreDebugSettings, IMediaFileSystem mediaFileSystem, + IEventAggregator eventAggregator, ILogger logger, FileSystems fileSystems, Scope parent, @@ -151,7 +159,7 @@ namespace Umbraco.Cms.Core.Scoping bool? scopeFileSystems = null, bool callContext = false, bool autoComplete = false) - : this(scopeProvider, coreDebugSettings, mediaFileSystem, logger, fileSystems, parent, null, false, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete) + : this(scopeProvider, coreDebugSettings, mediaFileSystem, eventAggregator, logger, fileSystems, parent, null, false, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete) { } public Guid InstanceId { get; } = Guid.NewGuid(); @@ -314,6 +322,16 @@ namespace Umbraco.Cms.Core.Scoping } } + public IScopedNotificationPublisher Notifications + { + get + { + EnsureNotDisposed(); + if (ParentScope != null) return ParentScope.Notifications; + return _notificationPublisher ?? (_notificationPublisher = new ScopedNotificationPublisher(_eventAggregator)); + } + } + /// public bool Complete() { @@ -453,7 +471,10 @@ namespace Umbraco.Cms.Core.Scoping { // deal with events if (onException == false) + { _eventDispatcher?.ScopeExit(completed); + _notificationPublisher?.ScopeExit(completed); + } }, () => { // if *we* created it, then get rid of it diff --git a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs index b0b1868a0d..392028166d 100644 --- a/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs +++ b/src/Umbraco.Infrastructure/Scoping/ScopeProvider.cs @@ -26,8 +26,9 @@ namespace Umbraco.Cms.Core.Scoping private readonly FileSystems _fileSystems; private readonly CoreDebugSettings _coreDebugSettings; private readonly IMediaFileSystem _mediaFileSystem; + private readonly IEventAggregator _eventAggregator; - public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, IOptions coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ILoggerFactory loggerFactory, IRequestCache requestCache) + public ScopeProvider(IUmbracoDatabaseFactory databaseFactory, FileSystems fileSystems, IOptions coreDebugSettings, IMediaFileSystem mediaFileSystem, ILogger logger, ILoggerFactory loggerFactory, IRequestCache requestCache, IEventAggregator eventAggregator) { DatabaseFactory = databaseFactory; _fileSystems = fileSystems; @@ -36,6 +37,7 @@ namespace Umbraco.Cms.Core.Scoping _logger = logger; _loggerFactory = loggerFactory; _requestCache = requestCache; + _eventAggregator = eventAggregator; // take control of the FileSystems _fileSystems.IsScoped = () => AmbientScope != null && AmbientScope.ScopedFileSystems; @@ -253,7 +255,7 @@ namespace Umbraco.Cms.Core.Scoping IEventDispatcher eventDispatcher = null, bool? scopeFileSystems = null) { - return new Scope(this, _coreDebugSettings, _mediaFileSystem, _loggerFactory.CreateLogger(), _fileSystems, true, null, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems); + return new Scope(this, _coreDebugSettings, _mediaFileSystem, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, true, null, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems); } /// @@ -309,13 +311,13 @@ namespace Umbraco.Cms.Core.Scoping { var ambientContext = AmbientContext; var newContext = ambientContext == null ? new ScopeContext() : null; - var scope = new Scope(this, _coreDebugSettings, _mediaFileSystem, _loggerFactory.CreateLogger(), _fileSystems, false, newContext, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete); + var scope = new Scope(this, _coreDebugSettings, _mediaFileSystem, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, false, newContext, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete); // assign only if scope creation did not throw! SetAmbient(scope, newContext ?? ambientContext); return scope; } - var nested = new Scope(this, _coreDebugSettings, _mediaFileSystem, _loggerFactory.CreateLogger(), _fileSystems, ambientScope, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete); + var nested = new Scope(this, _coreDebugSettings, _mediaFileSystem, _eventAggregator, _loggerFactory.CreateLogger(), _fileSystems, ambientScope, isolationLevel, repositoryCacheMode, eventDispatcher, scopeFileSystems, callContext, autoComplete); SetAmbient(nested, AmbientContext); return nested; } diff --git a/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs b/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs index da24ac4427..dbd6cce1c1 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/ContentService.cs @@ -33,7 +33,6 @@ namespace Umbraco.Cms.Core.Services.Implement private readonly IShortStringHelper _shortStringHelper; private readonly ILogger _logger; private IQuery _queryNotTrashed; - private readonly IEventAggregator _eventAggregator; #region Constructors @@ -41,7 +40,7 @@ namespace Umbraco.Cms.Core.Services.Implement IEventMessagesFactory eventMessagesFactory, IDocumentRepository documentRepository, IEntityRepository entityRepository, IAuditRepository auditRepository, IContentTypeRepository contentTypeRepository, IDocumentBlueprintRepository documentBlueprintRepository, ILanguageRepository languageRepository, - Lazy propertyValidationService, IShortStringHelper shortStringHelper, IEventAggregator eventAggregator) + Lazy propertyValidationService, IShortStringHelper shortStringHelper) : base(provider, loggerFactory, eventMessagesFactory) { _documentRepository = documentRepository; @@ -52,7 +51,6 @@ namespace Umbraco.Cms.Core.Services.Implement _languageRepository = languageRepository; _propertyValidationService = propertyValidationService; _shortStringHelper = shortStringHelper; - _eventAggregator = eventAggregator; _logger = loggerFactory.CreateLogger(); } @@ -750,15 +748,10 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - if (raiseEvents) + if (raiseEvents && scope.Notifications.PublishCancelable(new SavingNotification(content, evtMsgs))) { - var notification = new SavingNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) - { - scope.Complete(); - return OperationResult.Cancel(evtMsgs); - } + scope.Complete(); + return OperationResult.Cancel(evtMsgs); } scope.WriteLock(Cms.Core.Constants.Locks.ContentTree); @@ -780,7 +773,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { - _eventAggregator.Publish(new SavedNotification(content, evtMsgs)); + scope.Notifications.Publish(new SavedNotification(content, evtMsgs)); } var changeType = TreeChangeTypes.RefreshNode; scope.Events.Dispatch(TreeChanged, this, new TreeChange(content, changeType).ToEventArgs()); @@ -809,15 +802,10 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - if (raiseEvents) + if (raiseEvents && scope.Notifications.PublishCancelable(new SavingNotification(contentsA, evtMsgs))) { - var notification = new SavingNotification(contentsA, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) - { - scope.Complete(); - return OperationResult.Cancel(evtMsgs); - } + scope.Complete(); + return OperationResult.Cancel(evtMsgs); } var treeChanges = contentsA.Select(x => new TreeChange(x, TreeChangeTypes.RefreshNode)); @@ -834,7 +822,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { - _eventAggregator.Publish(new SavedNotification(contentsA, evtMsgs)); + scope.Notifications.Publish(new SavedNotification(contentsA, evtMsgs)); } scope.Events.Dispatch(TreeChanged, this, treeChanges.ToEventArgs()); Audit(AuditType.Save, userId == -1 ? 0 : userId, Cms.Core.Constants.System.Root, "Saved multiple content"); @@ -878,9 +866,7 @@ namespace Umbraco.Cms.Core.Services.Implement var allLangs = _languageRepository.GetMany().ToList(); - var notification = new SavingNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new SavingNotification(content, evtMsgs))) { return new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, content); } @@ -920,14 +906,9 @@ namespace Umbraco.Cms.Core.Services.Implement var evtMsgs = EventMessagesFactory.Get(); - if (raiseEvents) + if (raiseEvents && scope.Notifications.PublishCancelable(new SavingNotification(content, evtMsgs))) { - var notification = new SavingNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) - { - return new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, content); - } + return new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, content); } var varies = content.ContentType.VariesByCulture(); @@ -990,9 +971,7 @@ namespace Umbraco.Cms.Core.Services.Implement var allLangs = _languageRepository.GetMany().ToList(); - var notification = new SavingNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new SavingNotification(content, evtMsgs))) { return new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, content); } @@ -1063,9 +1042,7 @@ namespace Umbraco.Cms.Core.Services.Implement scope.WriteLock(Cms.Core.Constants.Locks.ContentTree); - var notification = new SavingNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new SavingNotification(content, evtMsgs))) { return new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, content); } @@ -1235,7 +1212,7 @@ namespace Umbraco.Cms.Core.Services.Implement // raise the Saved event, always if (raiseEvents) { - _eventAggregator.Publish(new SavedNotification(content, evtMsgs)); + scope.Notifications.Publish(new SavedNotification(content, evtMsgs)); } if (unpublishing) // we have tried to unpublish - won't happen in a branch @@ -1243,7 +1220,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (unpublishResult.Success) // and succeeded, trigger events { // events and audit - _eventAggregator.Publish(new UnpublishedNotification(content, evtMsgs)); + scope.Notifications.Publish(new UnpublishedNotification(content, evtMsgs)); scope.Events.Dispatch(TreeChanged, this, new TreeChange(content, TreeChangeTypes.RefreshBranch).ToEventArgs()); if (culturesUnpublishing != null) @@ -1298,7 +1275,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (!branchOne) // for branches, handled by SaveAndPublishBranch { scope.Events.Dispatch(TreeChanged, this, new TreeChange(content, changeType).ToEventArgs()); - _eventAggregator.Publish(new PublishedNotification(content, evtMsgs)); + scope.Notifications.Publish(new PublishedNotification(content, evtMsgs)); } // it was not published and now is... descendants that were 'published' (but @@ -1307,7 +1284,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (!branchOne && isNew == false && previouslyPublished == false && HasChildren(content.Id)) { var descendants = GetPublishedDescendantsLocked(content).ToArray(); - _eventAggregator.Publish(new PublishedNotification(descendants, evtMsgs)); + scope.Notifications.Publish(new PublishedNotification(descendants, evtMsgs)); } switch (publishResult.Result) @@ -1400,9 +1377,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (pendingCultures.Count == 0) continue; //shouldn't happen but no point in processing this document if there's nothing there - var notification = new SavingNotification(d, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new SavingNotification(d, evtMsgs))) { results.Add(new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, d)); continue; @@ -1462,9 +1437,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (pendingCultures.Count == 0) continue; //shouldn't happen but no point in processing this document if there's nothing there - var notification = new SavingNotification(d, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new SavingNotification(d, evtMsgs))) { results.Add(new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, d)); continue; @@ -1721,7 +1694,7 @@ namespace Umbraco.Cms.Core.Services.Implement // trigger events for the entire branch // (SaveAndPublishBranchOne does *not* do it) scope.Events.Dispatch(TreeChanged, this, new TreeChange(document, TreeChangeTypes.RefreshBranch).ToEventArgs()); - _eventAggregator.Publish(new PublishedNotification(publishedDocuments, evtMsgs)); + scope.Notifications.Publish(new PublishedNotification(publishedDocuments, evtMsgs)); scope.Complete(); } @@ -1745,9 +1718,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (culturesToPublish.Count == 0) // empty = already published return new PublishResult(PublishResultType.SuccessPublishAlready, evtMsgs, document); - var notification = new SavingNotification(document, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new SavingNotification(document, evtMsgs))) { return new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, document); } @@ -1776,9 +1747,7 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - var notification = new DeletingNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new DeletingNotification(content, evtMsgs))) { scope.Complete(); return OperationResult.Cancel(evtMsgs); @@ -1791,7 +1760,7 @@ namespace Umbraco.Cms.Core.Services.Implement // just raise the event if (content.Trashed == false && content.Published) { - _eventAggregator.Publish(new UnpublishedNotification(content, evtMsgs)); + scope.Notifications.Publish(new UnpublishedNotification(content, evtMsgs)); } DeleteLocked(scope, content, evtMsgs); @@ -1810,7 +1779,7 @@ namespace Umbraco.Cms.Core.Services.Implement void DoDelete(IContent c) { _documentRepository.Delete(c); - _eventAggregator.Publish(new DeletedNotification(c, evtMsgs)); + scope.Notifications.Publish(new DeletedNotification(c, evtMsgs)); // media files deleted by QueuingEventDispatcher } @@ -1845,9 +1814,7 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - var notification = new DeletingVersionsNotification(id, evtMsgs, dateToRetain: versionDate); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new DeletingVersionsNotification(id, evtMsgs, dateToRetain: versionDate))) { scope.Complete(); return; @@ -1856,7 +1823,7 @@ namespace Umbraco.Cms.Core.Services.Implement scope.WriteLock(Cms.Core.Constants.Locks.ContentTree); _documentRepository.DeleteVersions(id, versionDate); - _eventAggregator.Publish(new DeletedVersionsNotification(id, evtMsgs, dateToRetain: versionDate)); + scope.Notifications.Publish(new DeletedVersionsNotification(id, evtMsgs, dateToRetain: versionDate)); Audit(AuditType.Delete, userId, Cms.Core.Constants.System.Root, "Delete (by version date)"); scope.Complete(); @@ -1877,9 +1844,7 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - var notification = new DeletingVersionsNotification(id, evtMsgs, specificVersion: versionId); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new DeletingVersionsNotification(id, evtMsgs, specificVersion: versionId))) { scope.Complete(); return; @@ -1896,7 +1861,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (c.VersionId != versionId && c.PublishedVersionId != versionId) // don't delete the current or published version _documentRepository.DeleteVersion(versionId); - _eventAggregator.Publish(new DeletedVersionsNotification(id, evtMsgs, specificVersion: versionId)); + scope.Notifications.Publish(new DeletedVersionsNotification(id, evtMsgs, specificVersion: versionId)); Audit(AuditType.Delete, userId, Cms.Core.Constants.System.Root, "Delete (by version)"); scope.Complete(); @@ -1920,9 +1885,7 @@ namespace Umbraco.Cms.Core.Services.Implement var originalPath = content.Path; var moveEventInfo = new MoveEventInfo(content, originalPath, Cms.Core.Constants.System.RecycleBinContent); - var notification = new MovingToRecycleBinNotification(moveEventInfo, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new MovingToRecycleBinNotification(moveEventInfo, evtMsgs))) { scope.Complete(); return OperationResult.Cancel(evtMsgs); // causes rollback @@ -1941,7 +1904,7 @@ namespace Umbraco.Cms.Core.Services.Implement .Select(x => new MoveEventInfo(x.Item1, x.Item2, x.Item1.ParentId)) .ToArray(); - _eventAggregator.Publish(new MovedToRecycleBinNotification(moveInfo, evtMsgs)); + scope.Notifications.Publish(new MovedToRecycleBinNotification(moveInfo, evtMsgs)); Audit(AuditType.Move, userId, content.Id, "Moved to recycle bin"); scope.Complete(); @@ -1983,9 +1946,8 @@ namespace Umbraco.Cms.Core.Services.Implement throw new InvalidOperationException("Parent does not exist or is trashed."); // causes rollback var moveEventInfo = new MoveEventInfo(content, content.Path, parentId); - var notification = new MovingNotification(moveEventInfo, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + + if (scope.Notifications.PublishCancelable(new MovingNotification(moveEventInfo, evtMsgs))) { scope.Complete(); return; // causes rollback @@ -2014,7 +1976,7 @@ namespace Umbraco.Cms.Core.Services.Implement .Select(x => new MoveEventInfo(x.Item1, x.Item2, x.Item1.ParentId)) .ToArray(); - _eventAggregator.Publish(new MovedNotification(moveInfo, evtMsgs)); + scope.Notifications.Publish(new MovedNotification(moveInfo, evtMsgs)); Audit(AuditType.Move, userId, content.Id); @@ -2099,9 +2061,7 @@ namespace Umbraco.Cms.Core.Services.Implement // are managed by Delete, and not here. // no idea what those events are for, keep a simplified version - var notification = new EmptyingRecycleBinNotification(evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new EmptyingRecycleBinNotification(evtMsgs))) { scope.Complete(); return OperationResult.Cancel(evtMsgs); @@ -2116,7 +2076,7 @@ namespace Umbraco.Cms.Core.Services.Implement deleted.Add(content); } - _eventAggregator.Publish(new EmptiedRecycleBinNotification(evtMsgs)); + scope.Notifications.Publish(new EmptiedRecycleBinNotification(evtMsgs)); scope.Events.Dispatch(TreeChanged, this, deleted.Select(x => new TreeChange(x, TreeChangeTypes.Remove)).ToEventArgs()); Audit(AuditType.Delete, userId, Cms.Core.Constants.System.RecycleBinContent, "Recycle bin emptied"); @@ -2163,9 +2123,7 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - var notification = new CopyingNotification(content, copy, parentId, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new CopyingNotification(content, copy, parentId, evtMsgs))) { scope.Complete(); return null; @@ -2220,9 +2178,7 @@ namespace Umbraco.Cms.Core.Services.Implement var descendantCopy = descendant.DeepCloneWithResetIdentities(); descendantCopy.ParentId = parentId; - notification = new CopyingNotification(descendant, descendantCopy, parentId, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new CopyingNotification(descendant, descendantCopy, parentId, evtMsgs))) { continue; } @@ -2250,7 +2206,7 @@ namespace Umbraco.Cms.Core.Services.Implement scope.Events.Dispatch(TreeChanged, this, new TreeChange(copy, TreeChangeTypes.RefreshBranch).ToEventArgs()); foreach (var x in copies) { - _eventAggregator.Publish(new CopiedNotification(x.Item1, x.Item2, parentId, relateToOriginal, evtMsgs)); + scope.Notifications.Publish(new CopiedNotification(x.Item1, x.Item2, parentId, relateToOriginal, evtMsgs)); } Audit(AuditType.Copy, userId, content.Id); @@ -2272,9 +2228,7 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - var notification = new SendingToPublishNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new SendingToPublishNotification(content, evtMsgs))) { scope.Complete(); return false; @@ -2299,7 +2253,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (!saveResult.Success) return saveResult.Success; - _eventAggregator.Publish(new SentToPublishNotification(content, evtMsgs)); + scope.Notifications.Publish(new SentToPublishNotification(content, evtMsgs)); if (culturesChanging != null) Audit(AuditType.SendToPublishVariant, userId, content.Id, $"Send To Publish for cultures: {culturesChanging}", culturesChanging); @@ -2374,17 +2328,13 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { // raise cancelable sorting event - var sortingNotification = new SortingNotification(itemsA, evtMsgs); - _eventAggregator.Publish(sortingNotification); - if (sortingNotification.Cancel) + if (scope.Notifications.PublishCancelable(new SortingNotification(itemsA, evtMsgs))) { return OperationResult.Cancel(evtMsgs); } - // raise cancelable saving event - var savingNotification = new SavingNotification(itemsA, evtMsgs); - _eventAggregator.Publish(savingNotification); - if (savingNotification.Cancel) + // raise cancelable saving event + if (scope.Notifications.PublishCancelable(new SavingNotification(itemsA, evtMsgs))) { return OperationResult.Cancel(evtMsgs); } @@ -2421,15 +2371,15 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { //first saved, then sorted - _eventAggregator.Publish(new SavedNotification(itemsA, evtMsgs)); - _eventAggregator.Publish(new SortedNotification(itemsA, evtMsgs)); + scope.Notifications.Publish(new SavedNotification(itemsA, evtMsgs)); + scope.Notifications.Publish(new SortedNotification(itemsA, evtMsgs)); } scope.Events.Dispatch(TreeChanged, this, saved.Select(x => new TreeChange(x, TreeChangeTypes.RefreshNode)).ToEventArgs()); if (raiseEvents && published.Any()) { - _eventAggregator.Publish(new PublishedNotification(published, evtMsgs)); + scope.Notifications.Publish(new PublishedNotification(published, evtMsgs)); } Audit(AuditType.Sort, userId, 0, "Sorting content performed by user"); @@ -2534,9 +2484,7 @@ namespace Umbraco.Cms.Core.Services.Implement IReadOnlyCollection culturesUnpublishing, EventMessages evtMsgs, IReadOnlyCollection allLangs) { // raise Publishing notification - var notification = new PublishingNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new PublishingNotification(content, evtMsgs))) { _logger.LogInformation("Document {ContentName} (id={ContentId}) cannot be published: {Reason}", content.Name, content.Id, "publishing was cancelled"); return new PublishResult(PublishResultType.FailedPublishCancelledByEvent, evtMsgs, content); @@ -2696,9 +2644,7 @@ namespace Umbraco.Cms.Core.Services.Implement private PublishResult StrategyCanUnpublish(IScope scope, IContent content, EventMessages evtMsgs) { // raise Unpublishing notification - var notification = new UnpublishingNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new UnpublishingNotification(content, evtMsgs))) { _logger.LogInformation("Document {ContentName} (id={ContentId}) cannot be unpublished: unpublishing was cancelled.", content.Name, content.Id); return new PublishResult(PublishResultType.FailedUnpublishCancelledByEvent, evtMsgs, content); @@ -2780,9 +2726,7 @@ namespace Umbraco.Cms.Core.Services.Implement var query = Query().WhereIn(x => x.ContentTypeId, contentTypeIdsA); var contents = _documentRepository.Get(query).ToArray(); - var notification = new DeletingNotification(contents, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new DeletingNotification(contents, evtMsgs))) { scope.Complete(); return; @@ -2797,7 +2741,7 @@ namespace Umbraco.Cms.Core.Services.Implement // just raise the event if (content.Trashed == false && content.Published) { - _eventAggregator.Publish(new UnpublishedNotification(content, evtMsgs)); + scope.Notifications.Publish(new UnpublishedNotification(content, evtMsgs)); } // if current content has children, move them to trash @@ -2822,7 +2766,7 @@ namespace Umbraco.Cms.Core.Services.Implement .ToArray(); if (moveInfos.Length > 0) { - _eventAggregator.Publish(new MovedToRecycleBinNotification(moveInfos, evtMsgs)); + scope.Notifications.Publish(new MovedToRecycleBinNotification(moveInfos, evtMsgs)); } scope.Events.Dispatch(TreeChanged, this, changes.ToEventArgs()); @@ -2922,7 +2866,7 @@ namespace Umbraco.Cms.Core.Services.Implement Audit(AuditType.Save, Cms.Core.Constants.Security.SuperUserId, content.Id, $"Saved content template: {content.Name}"); - _eventAggregator.Publish(new SavedBlueprintNotification(content, evtMsgs)); + scope.Notifications.Publish(new SavedBlueprintNotification(content, evtMsgs)); scope.Complete(); } @@ -2936,7 +2880,7 @@ namespace Umbraco.Cms.Core.Services.Implement { scope.WriteLock(Cms.Core.Constants.Locks.ContentTree); _documentBlueprintRepository.Delete(content); - _eventAggregator.Publish(new DeletedBlueprintNotification(content, evtMsgs)); + scope.Notifications.Publish(new DeletedBlueprintNotification(content, evtMsgs)); scope.Complete(); } } @@ -3028,7 +2972,7 @@ namespace Umbraco.Cms.Core.Services.Implement _documentBlueprintRepository.Delete(blueprint); } - _eventAggregator.Publish(new DeletedBlueprintNotification(blueprints, evtMsgs)); + scope.Notifications.Publish(new DeletedBlueprintNotification(blueprints, evtMsgs)); scope.Complete(); } } @@ -3063,9 +3007,7 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - var notification = new RollingBackNotification(content, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new RollingBackNotification(content, evtMsgs))) { scope.Complete(); return OperationResult.Cancel(evtMsgs); @@ -3085,7 +3027,7 @@ namespace Umbraco.Cms.Core.Services.Implement } else { - _eventAggregator.Publish(new RolledBackNotification(content, evtMsgs)); + scope.Notifications.Publish(new RolledBackNotification(content, evtMsgs)); //Logging & Audit message _logger.LogInformation("User '{UserId}' rolled back content '{ContentId}' to version '{VersionId}'", userId, id, versionId); diff --git a/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs b/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs index 4ccf48a690..0621e8dfbf 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/MediaService.cs @@ -31,13 +31,11 @@ namespace Umbraco.Cms.Core.Services.Implement private readonly IMediaFileSystem _mediaFileSystem; - private readonly IEventAggregator _eventAggregator; - #region Constructors public MediaService(IScopeProvider provider, IMediaFileSystem mediaFileSystem, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IMediaRepository mediaRepository, IAuditRepository auditRepository, IMediaTypeRepository mediaTypeRepository, - IEntityRepository entityRepository, IShortStringHelper shortStringHelper, IEventAggregator eventAggregator) + IEntityRepository entityRepository, IShortStringHelper shortStringHelper) : base(provider, loggerFactory, eventMessagesFactory) { _mediaFileSystem = mediaFileSystem; @@ -46,7 +44,6 @@ namespace Umbraco.Cms.Core.Services.Implement _mediaTypeRepository = mediaTypeRepository; _entityRepository = entityRepository; _shortStringHelper = shortStringHelper; - _eventAggregator = eventAggregator; } #endregion @@ -299,16 +296,14 @@ namespace Umbraco.Cms.Core.Services.Implement if (withIdentity) { - var notification = new SavingNotification(media, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new SavingNotification(media, evtMsgs))) { return; } _mediaRepository.Save(media); - _eventAggregator.Publish(new SavedNotification(media, evtMsgs)); + scope.Notifications.Publish(new SavedNotification(media, evtMsgs)); scope.Events.Dispatch(TreeChanged, this, new TreeChange(media, TreeChangeTypes.RefreshNode).ToEventArgs()); } @@ -666,15 +661,10 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - if (raiseEvents) + if (raiseEvents && scope.Notifications.PublishCancelable(new SavingNotification(media, evtMsgs))) { - var notification = new SavingNotification(media, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) - { - scope.Complete(); - return OperationResult.Attempt.Cancel(evtMsgs); - } + scope.Complete(); + return OperationResult.Attempt.Cancel(evtMsgs); } // poor man's validation? @@ -693,7 +683,7 @@ namespace Umbraco.Cms.Core.Services.Implement _mediaRepository.Save(media); if (raiseEvents) { - _eventAggregator.Publish(new SavedNotification(media, evtMsgs)); + scope.Notifications.Publish(new SavedNotification(media, evtMsgs)); } var changeType = TreeChangeTypes.RefreshNode; scope.Events.Dispatch(TreeChanged, this, new TreeChange(media, changeType).ToEventArgs()); @@ -718,15 +708,10 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - if (raiseEvents) + if (raiseEvents && scope.Notifications.PublishCancelable(new SavingNotification(mediasA, evtMsgs))) { - var notification = new SavingNotification(mediasA, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) - { - scope.Complete(); - return OperationResult.Attempt.Cancel(evtMsgs); - } + scope.Complete(); + return OperationResult.Attempt.Cancel(evtMsgs); } var treeChanges = mediasA.Select(x => new TreeChange(x, TreeChangeTypes.RefreshNode)); @@ -741,7 +726,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { - _eventAggregator.Publish(new SavedNotification(mediasA, evtMsgs)); + scope.Notifications.Publish(new SavedNotification(mediasA, evtMsgs)); } scope.Events.Dispatch(TreeChanged, this, treeChanges.ToEventArgs()); Audit(AuditType.Save, userId == -1 ? 0 : userId, Cms.Core.Constants.System.Root, "Bulk save media"); @@ -767,9 +752,7 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - var notification = new DeletingNotification(media, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new DeletingNotification(media, evtMsgs))) { scope.Complete(); return OperationResult.Attempt.Cancel(evtMsgs); @@ -793,7 +776,7 @@ namespace Umbraco.Cms.Core.Services.Implement void DoDelete(IMedia c) { _mediaRepository.Delete(c); - _eventAggregator.Publish(new DeletedNotification(c, evtMsgs)); + scope.Notifications.Publish(new DeletedNotification(c, evtMsgs)); // media files deleted by QueuingEventDispatcher } @@ -836,9 +819,7 @@ namespace Umbraco.Cms.Core.Services.Implement { var evtMsgs = EventMessagesFactory.Get(); - var notification = new DeletingVersionsNotification(id, evtMsgs, dateToRetain: versionDate); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new DeletingVersionsNotification(id, evtMsgs, dateToRetain: versionDate))) { return; } @@ -847,7 +828,7 @@ namespace Umbraco.Cms.Core.Services.Implement scope.WriteLock(Cms.Core.Constants.Locks.MediaTree); _mediaRepository.DeleteVersions(id, versionDate); - _eventAggregator.Publish(new DeletedVersionsNotification(id, evtMsgs, dateToRetain: versionDate)); + scope.Notifications.Publish(new DeletedVersionsNotification(id, evtMsgs, dateToRetain: versionDate)); Audit(AuditType.Delete, userId, Cms.Core.Constants.System.Root, "Delete Media by version date"); } @@ -865,9 +846,7 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - var notification = new DeletingVersionsNotification(id, evtMsgs, specificVersion: versionId); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new DeletingVersionsNotification(id, evtMsgs, specificVersion: versionId))) { scope.Complete(); return; @@ -885,7 +864,7 @@ namespace Umbraco.Cms.Core.Services.Implement _mediaRepository.DeleteVersion(versionId); - _eventAggregator.Publish(new DeletedVersionsNotification(id, evtMsgs, specificVersion: versionId)); + scope.Notifications.Publish(new DeletedVersionsNotification(id, evtMsgs, specificVersion: versionId)); Audit(AuditType.Delete, userId, Cms.Core.Constants.System.Root, "Delete Media by version"); scope.Complete(); @@ -917,9 +896,7 @@ namespace Umbraco.Cms.Core.Services.Implement var moveEventInfo = new MoveEventInfo(media, originalPath, Cms.Core.Constants.System.RecycleBinMedia); - var notification = new MovingToRecycleBinNotification(moveEventInfo, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new MovingToRecycleBinNotification(moveEventInfo, evtMsgs))) { scope.Complete(); return OperationResult.Attempt.Cancel(evtMsgs); @@ -928,9 +905,8 @@ namespace Umbraco.Cms.Core.Services.Implement PerformMoveLocked(media, Cms.Core.Constants.System.RecycleBinMedia, null, userId, moves, true); scope.Events.Dispatch(TreeChanged, this, new TreeChange(media, TreeChangeTypes.RefreshBranch).ToEventArgs()); - var moveInfo = moves.Select(x => new MoveEventInfo(x.Item1, x.Item2, x.Item1.ParentId)) - .ToArray(); - _eventAggregator.Publish(new MovedToRecycleBinNotification(moveInfo, evtMsgs)); + var moveInfo = moves.Select(x => new MoveEventInfo(x.Item1, x.Item2, x.Item1.ParentId)).ToArray(); + scope.Notifications.Publish(new MovedToRecycleBinNotification(moveInfo, evtMsgs)); Audit(AuditType.Move, userId, media.Id, "Move Media to recycle bin"); scope.Complete(); @@ -967,9 +943,7 @@ namespace Umbraco.Cms.Core.Services.Implement throw new InvalidOperationException("Parent does not exist or is trashed."); // causes rollback var moveEventInfo = new MoveEventInfo(media, media.Path, parentId); - var notification = new MovingNotification(moveEventInfo, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new MovingNotification(moveEventInfo, evtMsgs))) { scope.Complete(); return OperationResult.Attempt.Cancel(evtMsgs); @@ -985,7 +959,7 @@ namespace Umbraco.Cms.Core.Services.Implement var moveInfo = moves //changes .Select(x => new MoveEventInfo(x.Item1, x.Item2, x.Item1.ParentId)) .ToArray(); - _eventAggregator.Publish(new MovedNotification(moveInfo, evtMsgs)); + scope.Notifications.Publish(new MovedNotification(moveInfo, evtMsgs)); Audit(AuditType.Move, userId, media.Id); scope.Complete(); } @@ -1066,9 +1040,7 @@ namespace Umbraco.Cms.Core.Services.Implement // v7 EmptyingRecycleBin and EmptiedRecycleBin events are greatly simplified since // each deleted items will have its own deleting/deleted events. so, files and such // are managed by Delete, and not here. - var notification = new EmptyingRecycleBinNotification(evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new EmptyingRecycleBinNotification(evtMsgs))) { scope.Complete(); return OperationResult.Cancel(evtMsgs); @@ -1082,7 +1054,7 @@ namespace Umbraco.Cms.Core.Services.Implement DeleteLocked(scope, media, evtMsgs); deleted.Add(media); } - _eventAggregator.Publish(new EmptiedRecycleBinNotification(new EventMessages())); + scope.Notifications.Publish(new EmptiedRecycleBinNotification(new EventMessages())); scope.Events.Dispatch(TreeChanged, this, deleted.Select(x => new TreeChange(x, TreeChangeTypes.Remove)).ToEventArgs()); Audit(AuditType.Delete, userId, Cms.Core.Constants.System.RecycleBinMedia, "Empty Media recycle bin"); scope.Complete(); @@ -1112,15 +1084,10 @@ namespace Umbraco.Cms.Core.Services.Implement using (var scope = ScopeProvider.CreateScope()) { - if (raiseEvents) + if (raiseEvents && scope.Notifications.PublishCancelable(new SavingNotification(itemsA, evtMsgs))) { - var notification = new SavingNotification(itemsA, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) - { - scope.Complete(); - return false; - } + scope.Complete(); + return false; } var saved = new List(); @@ -1146,7 +1113,7 @@ namespace Umbraco.Cms.Core.Services.Implement if (raiseEvents) { - _eventAggregator.Publish(new SavedNotification(itemsA, evtMsgs)); + scope.Notifications.Publish(new SavedNotification(itemsA, evtMsgs)); } scope.Events.Dispatch(TreeChanged, this, saved.Select(x => new TreeChange(x, TreeChangeTypes.RefreshNode)).ToEventArgs()); Audit(AuditType.Sort, userId, 0); @@ -1264,9 +1231,7 @@ namespace Umbraco.Cms.Core.Services.Implement var query = Query().WhereIn(x => x.ContentTypeId, mediaTypeIdsA); var medias = _mediaRepository.Get(query).ToArray(); - var notification = new DeletingNotification(medias, evtMsgs); - _eventAggregator.Publish(notification); - if (notification.Cancel) + if (scope.Notifications.PublishCancelable(new DeletingNotification(medias, evtMsgs))) { scope.Complete(); return; @@ -1297,7 +1262,7 @@ namespace Umbraco.Cms.Core.Services.Implement .ToArray(); if (moveInfos.Length > 0) { - _eventAggregator.Publish(new MovedToRecycleBinNotification(moveInfos, evtMsgs)); + scope.Notifications.Publish(new MovedToRecycleBinNotification(moveInfos, evtMsgs)); } scope.Events.Dispatch(TreeChanged, this, changes.ToEventArgs()); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs index b06144d555..745e8309d7 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs @@ -17,6 +17,7 @@ using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Logging; @@ -50,7 +51,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Components var fs = new FileSystems(mock.Object, loggerFactory.CreateLogger(), loggerFactory, IOHelper, Options.Create(globalSettings), Mock.Of()); var coreDebug = new CoreDebugSettings(); IMediaFileSystem mediaFileSystem = Mock.Of(); - var p = new ScopeProvider(f, fs, Options.Create(coreDebug), mediaFileSystem, loggerFactory.CreateLogger(), loggerFactory, NoAppCache.Instance); + IEventAggregator eventAggregator = Mock.Of(); + var p = new ScopeProvider(f, fs, Options.Create(coreDebug), mediaFileSystem, loggerFactory.CreateLogger(), loggerFactory, NoAppCache.Instance, eventAggregator); mock.Setup(x => x.GetService(typeof(ILogger))).Returns(logger); mock.Setup(x => x.GetService(typeof(ILogger))).Returns(loggerFactory.CreateLogger); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/ScopeEventDispatcherTests.cs index 17bc26dc23..43d14677fa 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/ScopeEventDispatcherTests.cs @@ -87,7 +87,8 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Scoping Mock.Of(), Mock.Of>(), instance, - Mock.Of() + Mock.Of(), + Mock.Of() ); } diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 3d4f58fd18..6aefad7cc8 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -8,6 +8,7 @@ using NPoco; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.Migrations.Install; @@ -86,7 +87,8 @@ namespace Umbraco.Tests.TestHelpers fileSystems ??= new FileSystems(Current.Factory, loggerFactory.CreateLogger(), loggerFactory, TestHelper.IOHelper, Options.Create(globalSettings), TestHelper.GetHostingEnvironment()); var coreDebug = TestHelper.CoreDebugSettings; var mediaFileSystem = Mock.Of(); - return new ScopeProvider(databaseFactory, fileSystems, Options.Create(coreDebugSettings), mediaFileSystem, loggerFactory.CreateLogger(), loggerFactory, NoAppCache.Instance); + var eventAggregator = Mock.Of(); + return new ScopeProvider(databaseFactory, fileSystems, Options.Create(coreDebugSettings), mediaFileSystem, loggerFactory.CreateLogger(), loggerFactory, NoAppCache.Instance, eventAggregator); } }