When Lamar constructs an instance using a nested container, should it pass the nested container to the OnCreation lambda?
Currently, Lamar passes the root container.
The unit test below fails on the last check - but I think it should pass.
This is related to issue #324 which was closed. I do not have permission to re-open that ticket as suggested, so I added this one - which distills the issue:
using System;
using System.Diagnostics;
using Shouldly;
using Xunit;
namespace Lamar.Testing.Bugs
{
public class Bug_324_scoping_within_on_creation
{
public interface IWidget
{
}
public class Widget : IWidget
{
public Widget(){}
}
[Fact]
public void oncreation_should_receive_the_constructing_container()
{
IServiceContext containerPassedToOnCreationLambda = null;
var rootContainer = new Container(x =>
{
x.For<IWidget>().Use<Widget>()
.OnCreation((context, concrete) => {
containerPassedToOnCreationLambda = context;
return concrete;
})
.Scoped();
});
var rootWidget = rootContainer.GetInstance<IWidget>();
// The rootContainer should have been passed to the OnCreation lambda.
containerPassedToOnCreationLambda.ShouldBeSameAs(rootContainer);
var nestedContainer = rootContainer.GetNestedContainer();
var nestedWidget = nestedContainer.GetInstance<IWidget>();
// The nestedContainer should have been passed to the OnCreation lambda.
containerPassedToOnCreationLambda.ShouldBeSameAs(nestedContainer);
}
}
}
When Lamar constructs an instance using a nested container, should it pass the nested container to the OnCreation lambda?
Currently, Lamar passes the root container.
The unit test below fails on the last check - but I think it should pass.
This is related to issue #324 which was closed. I do not have permission to re-open that ticket as suggested, so I added this one - which distills the issue: