Test below fails on last Assert() with this message:
Expected: “arg2”
But was: “arg1”
It seems when "arg1" passed first time – typed factory remembers this and ignores "arg2" from second call. Why?
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);
}
For windsor components are singletons by default. Your
Eis a singleton because you didn’t specify anything else. The second call does not ignore the argument but reuses the previous instance because it is a singleton.You have to define that
Eis a transient: