views:

102

answers:

1

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? My German isn't good enough to read the documentation.

[Test]
public void JellybeanDispenserHasNewInstanceEachTimeWithDefault()
{
    var builder = new ContainerBuilder();
    builder.DefaultControlledBy<TransientLifecycle>();
    builder.Register<IJellybeanDispenser, VanillaJellybeanDispenser>();
    builder.Register<SweetVendingMachine>().ControlledBy<TransientLifecycle>();
    builder.Register<SweetShop>();

    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");
}
+1  A: 

Hi there

@Anthony Thanks for reporting the issue, that helps me a alot!

The bug should be fixed. Bugfix and integration test are commited to the official svn repository at: http://lightcore.peterbucher.ch/download.aspx

Update: LightCore 1.4 is now available on the mentioned site above, the bug is fixed in this release,

Peter Bucher
Thanks! I have moved the "builder.DefaultControlledBy" line to before the registrations, since I think this makes a difference. Does it?
Anthony
Yes, i use deferred execution of the registration code, but the used variable for "DefaultLifecycle, e.g. Singleton" is captured right on the registration itself.That means, all statements after a new line of "DefaultControlledBy" use that lifecycle.Thanks for your attention, i will add a comment in the documentation on this.
Peter Bucher