Skip to content

Commit

Permalink
Merge pull request #1059 from alistairjevans/develop
Browse files Browse the repository at this point in the history
Add test for lifetime scope build callbacks nested inside module build callback
  • Loading branch information
tillig authored Dec 16, 2019
2 parents 83ab65c + 607f091 commit b837daf
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/Autofac.Specification.Test/ContainerBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,37 @@ void BuildCallback(ILifetimeScope c)
.RegisterBuildCallback(BuildCallback);
}
}

private class NestingModule : Module
{
public bool OuterBuildCallback { get; set; }

public bool InnerBuildCallback { get; set; }

protected override void Load(ContainerBuilder containerBuilder)
{
containerBuilder.RegisterBuildCallback(container =>
{
OuterBuildCallback = true;
var appScope = container.BeginLifetimeScope(nestedBuilder =>
{
nestedBuilder.RegisterBuildCallback((c) => {
InnerBuildCallback = true;
});
});
});
}
}

[Fact]
public void CheckLifetimeScopeBuilderNestedInsideModule()
{
var builder = new ContainerBuilder();
var mod = new NestingModule();
builder.RegisterModule(mod);
builder.Build();
Assert.True(mod.OuterBuildCallback);
Assert.True(mod.InnerBuildCallback);
}
}
}

0 comments on commit b837daf

Please sign in to comment.