Skip to content

Commit

Permalink
Test to ensure child scopes have independent event delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
eugbaranov committed Oct 31, 2018
1 parent 997153d commit 3266995
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/Autofac.Test/ModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Autofac.Builder;
using Autofac.Core;
using Autofac.Core.Registration;
using Xunit;
Expand Down Expand Up @@ -95,6 +96,34 @@ public void AttachesToRegistrationsInNestedScope()
}
}

[Fact]
public void ModifiedScopesHaveTheirOwnDelegate()
{
var attachingModule = new AttachingModule();
Assert.Equal(0, attachingModule.Registrations.Count);

var builder = new ContainerBuilder();
builder.RegisterModule(attachingModule);

using (var container = builder.Build())
{
Assert.NotNull(container.ComponentRegistry.Properties[MetadataKeys.RegisteredPropertyKey]);
using (var outerScope = container.BeginLifetimeScope(c => c.RegisterType(typeof(int))))
{
Assert.Equal(
container.ComponentRegistry.Properties[MetadataKeys.RegisteredPropertyKey],
outerScope.ComponentRegistry.Properties[MetadataKeys.RegisteredPropertyKey]);
outerScope.ComponentRegistry.Registered += (s, e) => { };
using (var innerScope = outerScope.BeginLifetimeScope())
{
Assert.NotEqual(
container.ComponentRegistry.Properties[MetadataKeys.RegisteredPropertyKey],
innerScope.ComponentRegistry.Properties[MetadataKeys.RegisteredPropertyKey]);
}
}
}
}

internal class ModuleExposingThisAssembly : Module
{
public Assembly ModuleThisAssembly
Expand Down

0 comments on commit 3266995

Please sign in to comment.