Skip to content

Commit

Permalink
Test for Activating ReplaceInstance()
Browse files Browse the repository at this point in the history
  • Loading branch information
VonOgre committed Apr 28, 2020
1 parent 70df799 commit 1bb9bde
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ public void ChainedOnActivatingEventsAreInvokedWithinASingleResolveOperation()
Assert.True(secondEventRaised);
}

[Fact]
public void MultilpeOnActivatingEventsCanPassReplacementOnward()
{
var builder = new ContainerBuilder();

var activatingInstances = new List<object>();

builder.RegisterType<AService>()
.OnActivating(e =>
{
activatingInstances.Add(e.Instance);
e.ReplaceInstance(new AServiceChild());
})
.OnActivating(e => activatingInstances.Add(e.Instance));

var container = builder.Build();
var result = container.Resolve<AService>();

Assert.IsType<AServiceChild>(result);
Assert.Equal(2, activatingInstances.Count);
Assert.IsType<AService>(activatingInstances[0]);
Assert.IsType<AServiceChild>(activatingInstances[1]);
}

[Fact]
public void ChainedOnActivatedEventsAreInvokedWithinASingleResolveOperation()
{
Expand Down Expand Up @@ -438,6 +462,10 @@ private class AService : IService
{
}

private class AServiceChild : AService
{
}

private class BService : IService
{
}
Expand Down

0 comments on commit 1bb9bde

Please sign in to comment.