Stu*_*ens 3 c# castle-windsor ioc-container
我有以下代码:
public interface IService { }
public class MyService : IService { }
Run Code Online (Sandbox Code Playgroud)
和测试方法
[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);
}
Run Code Online (Sandbox Code Playgroud)
我应该更改测试通过什么?
将生活方式设定为Transient:
container.Register(
Component.For<IService>()
.ImplementedBy<MyService>()
.LifeStyle.Transient
);
Run Code Online (Sandbox Code Playgroud)
默认的生活方式是Singleton,这就是你看到同一个实例的原因.
| 归档时间: |
|
| 查看次数: |
2099 次 |
| 最近记录: |