Lightcore IoC在应该给出一个新实例时返回相同的实例

时间:2010-06-12 19:42:58

标签: .net ioc-container

我使用lightcore IoC容器有以下代码。 但它失败了“NUnit.Framework.AssertionException:包含的对象是相等的”,这表明应该是瞬态的对象不是。

这是lightcore中的错误,还是我做错了?我的德语不够好阅读文档。

[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 个答案:

答案 0 :(得分:1)

@Anthony 感谢您报告此问题,这对我有很大帮助!

应该修复错误。修正和集成测试将提交到官方svn存储库:http://lightcore.ch/download.aspx

<强>更新: LightCore 1.4现已在上述网站上提供,此版本中的错误已修复