Skip to content

Commit

Permalink
Added test mentioned in issue autofac#511. Test passes, so issue closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Illig committed Oct 24, 2016
1 parent 1205272 commit 8ac5e2a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/Autofac.Test/Core/Lifetime/LifetimeScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,33 @@ public void NestedLifetimeScopesGetDisposedWhenParentIsDisposed()
Assert.True(tracker.IsDisposed, "The tracker should have been disposed along with the lifetime scope chain.");
}

[Fact]
public void TwoRegistrationsSameServicesDifferentLifetimeScopes()
{
// Issue #511
var builder = new ContainerBuilder();
builder.RegisterType<ServiceB1>().As<IServiceB>().As<IServiceCommon>();
builder.RegisterType<ServiceB1>().As<IServiceB>().InstancePerLifetimeScope();
using (var container = builder.Build())
{
using (var lifetimeScope = container.BeginLifetimeScope())
{
var obj1 = lifetimeScope.Resolve<IServiceB>();
var obj2 = lifetimeScope.Resolve<IServiceB>();
Assert.Same(obj1, obj2);
}

using (var lifetimeScope = container.BeginLifetimeScope(x => { }))
{
// Issue #511 mentions that passing a lambda configuration
// expression causes the test to fail.
var obj1 = lifetimeScope.Resolve<IServiceB>();
var obj2 = lifetimeScope.Resolve<IServiceB>();
Assert.Same(obj1, obj2);
}
}
}

public class Person
{
}
Expand Down

0 comments on commit 8ac5e2a

Please sign in to comment.