I have the following code:
public interface IService { }
public class MyService : IService { }
and a test method
[Test]
public void T1()
{
IWindsorContainer container = new WindsorContainer();
container.Register(Component.For<IService>()
.ImplementedBy<MyService>());
var s1 = container.Resolve<IService>();
var s2 = container.Resolve<IService>();
Assert.AreNotSame(s1, s2);
}
What should I change for the test to pass?
Set the lifestyle to Transient
:
container.Register(
Component.For<IService>()
.ImplementedBy<MyService>()
.LifeStyle.Transient
);
The default lifestyle is Singleton
and that's why you see the same instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With