From 1701eb2450d882d05a5bfd2a56e2669e6c0a7b63 Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 20 Jan 2017 17:05:22 +0100 Subject: [PATCH] u4-9322 - events cleanup --- src/Umbraco.Core/Events/ScopedEventManager.cs | 6 ++---- .../Repositories/ServerRegistrationRepository.cs | 2 +- .../Persistence/UnitOfWork/PetaPocoUnitOfWork.cs | 2 +- src/Umbraco.Core/Scoping/NoScope.cs | 2 +- .../Scoping/NoScopedEventManagerTests.cs | 16 ++++++++-------- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Core/Events/ScopedEventManager.cs b/src/Umbraco.Core/Events/ScopedEventManager.cs index 3f8409e08a..8b34454f27 100644 --- a/src/Umbraco.Core/Events/ScopedEventManager.cs +++ b/src/Umbraco.Core/Events/ScopedEventManager.cs @@ -19,14 +19,14 @@ namespace Umbraco.Core.Events } public void TrackEvent(TypedEventHandler e, TSender sender, TEventArgs args) - { + { _tracked.Add(new EventDefinition(e, sender, args)); } public IEnumerable GetEvents() { return _tracked; - } + } private readonly List _tracked = new List(); @@ -39,7 +39,5 @@ namespace Umbraco.Core.Events { _tracked.Clear(); } - - } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/ServerRegistrationRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ServerRegistrationRepository.cs index 7d33697e72..e3fad1aaf7 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ServerRegistrationRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ServerRegistrationRepository.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core.Persistence.Repositories { private readonly ICacheProvider _globalCache; - public ServerRegistrationRepository(IDatabaseUnitOfWork work, ICacheProvider staticCache, ILogger logger, ISqlSyntaxProvider sqlSyntax) + public ServerRegistrationRepository(IScopeUnitOfWork work, ICacheProvider globalCache, ILogger logger, ISqlSyntaxProvider sqlSyntax) : base(work, CacheHelper.NoCache, logger, sqlSyntax) { // managing the cache our own way (no policy etc) diff --git a/src/Umbraco.Core/Persistence/UnitOfWork/PetaPocoUnitOfWork.cs b/src/Umbraco.Core/Persistence/UnitOfWork/PetaPocoUnitOfWork.cs index 6276898afc..79d6357625 100644 --- a/src/Umbraco.Core/Persistence/UnitOfWork/PetaPocoUnitOfWork.cs +++ b/src/Umbraco.Core/Persistence/UnitOfWork/PetaPocoUnitOfWork.cs @@ -158,7 +158,7 @@ namespace Umbraco.Core.Persistence.UnitOfWork public IEventManager EventManager { - get { return ThisScope.EventManager; } + get { return Scope.Events; } } #region Operation diff --git a/src/Umbraco.Core/Scoping/NoScope.cs b/src/Umbraco.Core/Scoping/NoScope.cs index 5e5c8aab21..d1eaa140f9 100644 --- a/src/Umbraco.Core/Scoping/NoScope.cs +++ b/src/Umbraco.Core/Scoping/NoScope.cs @@ -79,7 +79,7 @@ namespace Umbraco.Core.Scoping } /// - public IEventManager EventManager + public IEventManager Events { get { diff --git a/src/Umbraco.Tests/Scoping/NoScopedEventManagerTests.cs b/src/Umbraco.Tests/Scoping/NoScopedEventManagerTests.cs index 6975b578ab..ce9266b9f2 100644 --- a/src/Umbraco.Tests/Scoping/NoScopedEventManagerTests.cs +++ b/src/Umbraco.Tests/Scoping/NoScopedEventManagerTests.cs @@ -17,7 +17,7 @@ namespace Umbraco.Tests.Scoping public void Does_Support_Event_Cancellation() { var scopeProvider = new ScopeProvider(Mock.Of()); - Assert.IsTrue(scopeProvider.AmbientOrNoScope.EventManager.SupportsEventCancellation); + Assert.IsTrue(scopeProvider.AmbientOrNoScope.Events.SupportsEventCancellation); } [Test] @@ -41,9 +41,9 @@ namespace Umbraco.Tests.Scoping }; var scopeProvider = new ScopeProvider(Mock.Of()); - scopeProvider.AmbientOrNoScope.EventManager.TrackEvent(DoThing1, this, new EventArgs()); - scopeProvider.AmbientOrNoScope.EventManager.TrackEvent(DoThing2, this, new EventArgs()); - scopeProvider.AmbientOrNoScope.EventManager.TrackEvent(DoThing3, this, new EventArgs()); + scopeProvider.AmbientOrNoScope.Events.TrackEvent(DoThing1, this, new EventArgs()); + scopeProvider.AmbientOrNoScope.Events.TrackEvent(DoThing2, this, new EventArgs()); + scopeProvider.AmbientOrNoScope.Events.TrackEvent(DoThing3, this, new EventArgs()); Assert.AreEqual(3, counter); @@ -53,11 +53,11 @@ namespace Umbraco.Tests.Scoping public void Can_Not_Raise_Events_Later() { var scopeProvider = new ScopeProvider(Mock.Of()); - scopeProvider.AmbientOrNoScope.EventManager.TrackEvent(DoThing1, this, new EventArgs()); - scopeProvider.AmbientOrNoScope.EventManager.TrackEvent(DoThing2, this, new EventArgs()); - scopeProvider.AmbientOrNoScope.EventManager.TrackEvent(DoThing3, this, new EventArgs()); + scopeProvider.AmbientOrNoScope.Events.TrackEvent(DoThing1, this, new EventArgs()); + scopeProvider.AmbientOrNoScope.Events.TrackEvent(DoThing2, this, new EventArgs()); + scopeProvider.AmbientOrNoScope.Events.TrackEvent(DoThing3, this, new EventArgs()); - Assert.AreEqual(0, scopeProvider.AmbientOrNoScope.EventManager.GetEvents().Count()); + Assert.AreEqual(0, scopeProvider.AmbientOrNoScope.Events.GetEvents().Count()); } public event EventHandler DoThing1;