Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmus committed May 29, 2017
2 parents 62ebc63 + 974a039 commit 4b87c01
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
9 changes: 8 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
### New in 0.45 (not released yet)
### New in 0.46 (not released 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)

* Breaking: Asynchronous subscribers are now **disabled by default**, i.e.,
any implementations of `ISubscribeAsynchronousTo<,,>` wont get invoked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,49 @@
using EventFlow.Configuration;
using EventFlow.TestHelpers;
using EventFlow.TestHelpers.Suites;
using FluentAssertions;
using Moq;
using NUnit.Framework;

namespace EventFlow.Autofac.Tests.UnitTests
{
[Category(Categories.Unit)]
public class AutofacServiceRegistrationTests : TestSuiteForServiceRegistration
{
[Test]
public void ValidateRegistrationsShouldDispose()
{
// Arrange
var service = new Mock<I>();
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<I>();
createdCount.Should().Be(2);
resolvedService.Should().BeSameAs(service.Object);

using (var scopedResolver = resolver.BeginScope())
{
var nestedResolvedService = scopedResolver.Resolve<I>();
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void AlwaysUnique()
Sut.Register<I, A>();

// Act
var resolver = Sut.CreateResolver(true);
var resolver = Sut.CreateResolver(false);
var i1 = resolver.Resolve<I>();
var i2 = resolver.Resolve<I>();

Expand Down
19 changes: 11 additions & 8 deletions Source/EventFlow/Extensions/ResolverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exception>();
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);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4b87c01

Please sign in to comment.