Lightcore IoC is returning the same instance when it should give a new one
- by Anthony
I have the following code using the lightcore IoC container.
But it fails with "NUnit.Framework.AssertionException: Contained objects are equal" which indicates that the objects that should be transient, are not. Is this a bug in lightcore, or am I doing it wrong?
[Test]
public void JellybeanDispenserHasNewInstanceEachTimeWithDefault()
{
var builder = new ContainerBuilder();
builder.Register<IJellybeanDispenser, VanillaJellybeanDispenser>();
builder.Register<SweetVendingMachine>().ControlledBy<TransientLifecycle>();
builder.Register<SweetShop>();
builder.DefaultControlledBy<TransientLifecycle>();
IContainer container = builder.Build();
SweetShop sweetShop = container.Resolve<SweetShop>();
SweetShop sweetShop2 = container.Resolve<SweetShop>();
Assert.IsFalse(ReferenceEquals(sweetShop, sweetShop2), "Root objects are equal");
Assert.IsFalse(ReferenceEquals(sweetShop.SweetVendingMachine, sweetShop2.SweetVendingMachine), "Contained objects are equal");
Assert.IsFalse(ReferenceEquals(sweetShop.SweetVendingMachine.JellybeanDispenser, sweetShop2.SweetVendingMachine.JellybeanDispenser), "services are equal");
}
PS: I would tag this question with "lightcore", but suddenly my reputation isn't good enough to make a new tag. Huh.