From af71dde02e873c38743f5947487f5663fa15ce58 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Sun, 28 May 2017 19:43:17 +0200 Subject: [PATCH 1/3] Version is now 0.46 --- RELEASE_NOTES.md | 6 +++++- appveyor.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 25b611213..d6088e641 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,4 +1,8 @@ -### New in 0.45 (not released yet) +### New in 0.46 (not released yet) + +* _Nothing yet_ + +### New in 0.45.2877 (released 2017-05-28) * Breaking: Asynchronous subscribers are now **disabled by default**, i.e., any implementations of `ISubscribeAsynchronousTo<,,>` wont get invoked diff --git a/appveyor.yml b/appveyor.yml index 4f148f418..667183cb5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ init: - git config --global core.autocrlf input -version: 0.45.{build} +version: 0.46.{build} install: - cmd: pip install -U Sphinx From 1052a415459d0ee948e9085209fa314f3c35970c Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Mon, 29 May 2017 18:38:57 +0200 Subject: [PATCH 2/3] When validating registrations, a lifetime scope should be used --- .../AutofacServiceRegistrationTests.cs | 36 +++++++++++++++++++ .../Suites/TestSuiteForServiceRegistration.cs | 2 +- .../Extensions/ResolverExtensions.cs | 19 +++++----- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Source/EventFlow.Autofac.Tests/UnitTests/AutofacServiceRegistrationTests.cs b/Source/EventFlow.Autofac.Tests/UnitTests/AutofacServiceRegistrationTests.cs index d233d5e65..5918e9666 100644 --- a/Source/EventFlow.Autofac.Tests/UnitTests/AutofacServiceRegistrationTests.cs +++ b/Source/EventFlow.Autofac.Tests/UnitTests/AutofacServiceRegistrationTests.cs @@ -25,6 +25,8 @@ using EventFlow.Configuration; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Suites; +using FluentAssertions; +using Moq; using NUnit.Framework; namespace EventFlow.Autofac.Tests.UnitTests @@ -32,6 +34,40 @@ namespace EventFlow.Autofac.Tests.UnitTests [Category(Categories.Unit)] public class AutofacServiceRegistrationTests : TestSuiteForServiceRegistration { + [Test] + public void ValidateRegistrationsShouldDispose() + { + // Arrange + var service = new Mock(); + var createdCount = 0; + Sut.Register(_ => + { + createdCount++; + return service.Object; + }); + + // Act and Assert + using (var resolver = Sut.CreateResolver(true)) + { + createdCount.Should().Be(1); + service.Verify(m => m.Dispose(), Times.Once); + + var resolvedService = resolver.Resolve(); + createdCount.Should().Be(2); + resolvedService.Should().BeSameAs(service.Object); + + using (var scopedResolver = resolver.BeginScope()) + { + var nestedResolvedService = scopedResolver.Resolve(); + createdCount.Should().Be(3); + nestedResolvedService.Should().BeSameAs(service.Object); + } + service.Verify(m => m.Dispose(), Times.Exactly(2)); + } + + service.Verify(m => m.Dispose(), Times.Exactly(3)); + } + protected override IServiceRegistration CreateSut() { return new AutofacServiceRegistration(); diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForServiceRegistration.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForServiceRegistration.cs index 5aa288147..198b3f750 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForServiceRegistration.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForServiceRegistration.cs @@ -187,7 +187,7 @@ public void AlwaysUnique() Sut.Register(); // Act - var resolver = Sut.CreateResolver(true); + var resolver = Sut.CreateResolver(false); var i1 = resolver.Resolve(); var i2 = resolver.Resolve(); diff --git a/Source/EventFlow/Extensions/ResolverExtensions.cs b/Source/EventFlow/Extensions/ResolverExtensions.cs index 2d33a0ebe..7d1620aa6 100644 --- a/Source/EventFlow/Extensions/ResolverExtensions.cs +++ b/Source/EventFlow/Extensions/ResolverExtensions.cs @@ -31,18 +31,21 @@ namespace EventFlow.Extensions public static class ResolverExtensions { public static void ValidateRegistrations( - this IResolver resolver) + this IRootResolver resolver) { var exceptions = new List(); - foreach (var type in resolver.GetRegisteredServices()) + using (var scopeResolver = resolver.BeginScope()) { - try + foreach (var type in scopeResolver.GetRegisteredServices()) { - resolver.Resolve(type); - } - catch (Exception ex) - { - exceptions.Add(ex); + try + { + scopeResolver.Resolve(type); + } + catch (Exception ex) + { + exceptions.Add(ex); + } } } From e106433873e6433aaf1241e082a5ff155043b916 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Mon, 29 May 2017 18:43:24 +0200 Subject: [PATCH 3/3] Updated release notes --- RELEASE_NOTES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d6088e641..c50371160 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,9 @@ ### New in 0.46 (not released yet) -* _Nothing yet_ +* Fix: EventFlow now uses a Autofac lifetime scope for validating service + registrations when `IEventFlowOpions.CreateResolver(true)` is invoked. + Previously services were created but never disposed as they were resolved + using the root container ### New in 0.45.2877 (released 2017-05-28)