diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs index 41195be9fe..a779e5adc4 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs @@ -35,7 +35,9 @@ namespace Umbraco.Cms.Core.Cache INotificationHandler, INotificationHandler, INotificationHandler, - INotificationHandler + INotificationHandler, + INotificationHandler, + INotificationHandler { private List _unbinders; @@ -72,12 +74,6 @@ namespace Umbraco.Cms.Core.Cache Bind(() => FileService.DeletedStylesheet += FileService_DeletedStylesheet, () => FileService.DeletedStylesheet -= FileService_DeletedStylesheet); - // bind to domain events - Bind(() => DomainService.Saved += DomainService_Saved, - () => DomainService.Saved -= DomainService_Saved); - Bind(() => DomainService.Deleted += DomainService_Deleted, - () => DomainService.Deleted -= DomainService_Deleted); - // bind to content type events Bind(() => ContentTypeService.Changed += ContentTypeService_Changed, () => ContentTypeService.Changed -= ContentTypeService_Changed); @@ -207,16 +203,20 @@ namespace Umbraco.Cms.Core.Cache #region DomainService - private void DomainService_Saved(IDomainService sender, SaveEventArgs e) + public void Handle(DomainSavedNotification notification) { - foreach (var entity in e.SavedEntities) + foreach (IDomain entity in notification.SavedEntities) + { _distributedCache.RefreshDomainCache(entity); + } } - private void DomainService_Deleted(IDomainService sender, DeleteEventArgs e) + public void Handle(DomainDeletedNotification notification) { - foreach (var entity in e.DeletedEntities) + foreach (IDomain entity in notification.DeletedEntities) + { _distributedCache.RemoveDomainCache(entity); + } } #endregion diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs index e9e7bf30af..f5c9a9dbfc 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs @@ -82,7 +82,9 @@ namespace Umbraco.Cms.Core.Compose .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() - .AddNotificationHandler(); + .AddNotificationHandler() + .AddNotificationHandler() + .AddNotificationHandler(); // add notification handlers for auditing builder diff --git a/src/Umbraco.Infrastructure/Services/Implement/DomainService.cs b/src/Umbraco.Infrastructure/Services/Implement/DomainService.cs index 2b7d964a13..0540c04d64 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/DomainService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/DomainService.cs @@ -4,6 +4,7 @@ using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Scoping; +using Umbraco.Cms.Infrastructure.Services.Notifications; namespace Umbraco.Cms.Core.Services.Implement { @@ -28,25 +29,24 @@ namespace Umbraco.Cms.Core.Services.Implement public Attempt Delete(IDomain domain) { - var evtMsgs = EventMessagesFactory.Get(); + EventMessages eventMessages = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (IScope scope = ScopeProvider.CreateScope()) { - var deleteEventArgs = new DeleteEventArgs(domain, evtMsgs); - if (scope.Events.DispatchCancelable(Deleting, this, deleteEventArgs)) + var deletingNotification = new DomainDeletingNotification(domain, eventMessages); + if (scope.Notifications.PublishCancelable(deletingNotification)) { scope.Complete(); - return OperationResult.Attempt.Cancel(evtMsgs); + return OperationResult.Attempt.Cancel(eventMessages); } _domainRepository.Delete(domain); scope.Complete(); - deleteEventArgs.CanCancel = false; - scope.Events.Dispatch(Deleted, this, deleteEventArgs); + scope.Notifications.Publish(new DomainDeletedNotification(domain, eventMessages).WithStateFrom(deletingNotification)); } - return OperationResult.Attempt.Succeed(evtMsgs); + return OperationResult.Attempt.Succeed(eventMessages); } public IDomain GetByName(string name) @@ -83,48 +83,23 @@ namespace Umbraco.Cms.Core.Services.Implement public Attempt Save(IDomain domainEntity) { - var evtMsgs = EventMessagesFactory.Get(); + EventMessages eventMessages = EventMessagesFactory.Get(); - using (var scope = ScopeProvider.CreateScope()) + using (IScope scope = ScopeProvider.CreateScope()) { - var saveEventArgs = new SaveEventArgs(domainEntity, evtMsgs); - if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) + var savingNotification = new DomainSavingNotification(domainEntity, eventMessages); + if (scope.Notifications.PublishCancelable(savingNotification)) { scope.Complete(); - return OperationResult.Attempt.Cancel(evtMsgs); + return OperationResult.Attempt.Cancel(eventMessages); } _domainRepository.Save(domainEntity); scope.Complete(); - saveEventArgs.CanCancel = false; - scope.Events.Dispatch(Saved, this, saveEventArgs); + scope.Notifications.Publish(new DomainSavedNotification(domainEntity, eventMessages).WithStateFrom(savingNotification)); } - return OperationResult.Attempt.Succeed(evtMsgs); + return OperationResult.Attempt.Succeed(eventMessages); } - - #region Event Handlers - /// - /// Occurs before Delete - /// - public static event TypedEventHandler> Deleting; - - /// - /// Occurs after Delete - /// - public static event TypedEventHandler> Deleted; - - /// - /// Occurs before Save - /// - public static event TypedEventHandler> Saving; - - /// - /// Occurs after Save - /// - public static event TypedEventHandler> Saved; - - - #endregion } } diff --git a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs index 80488e91b1..d61a256638 100644 --- a/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests.Integration/Cache/DistributedCacheBinderTests.cs @@ -45,9 +45,6 @@ namespace Umbraco.Cms.Tests.Integration.Cache new EventDefinition>(null, FileService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, FileService, new DeleteEventArgs(Enumerable.Empty())), - new EventDefinition>(null, DomainService, new SaveEventArgs(Enumerable.Empty())), - new EventDefinition>(null, DomainService, new DeleteEventArgs(Enumerable.Empty())), - new EventDefinition>(null, ContentTypeService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, ContentTypeService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, MediaTypeService, new SaveEventArgs(Enumerable.Empty())),