下面的测试最后失败Assert()
并显示此消息:预期:“arg2”但原为:“arg1”
似乎在第一次通过时 - 类型化工厂会记住这一点并从第二次调用中"arg1"
忽略。"arg2"
为什么?
public class E
{
public string Arg { get; set; }
public E(string arg)
{
Arg = arg;
}
}
public interface IEFactory
{
E Create(string arg);
}
[Test]
public void TypedFactoryWorksAsExpected()
{
var windsor = new WindsorContainer();
windsor.Kernel.AddFacility<TypedFactoryFacility>();
windsor.Register(
Component.For<E>(),
Component.For<IEFactory>().AsFactory());
var factory = windsor.Resolve<IEFactory>();
var e1 = factory.Create("arg1");
var e2 = factory.Create("arg2");
Assert.AreEqual("arg1", e1.Arg);
// This line fails with message:
// 'Expected: "arg2" But was: "arg1".'
Assert.AreEqual("arg2", e2.Arg);
}