Lightcore IoC is returning the same instance when it should give a new one

Posted by Anthony on Stack Overflow See other posts from Stack Overflow or by Anthony
Published on 2010-06-12T19:42:57Z Indexed on 2010/06/12 19:53 UTC
Read the original article Hit count: 231

Filed under:

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.

© Stack Overflow or respective owner

Related posts about ioc-container