我正在寻找能够执行以下操作的IoC容器:
LifetimeProvider.Current
。IDependency
和Dependency
。IDependency
的值发生变化时,我希望LifetimeProvider.Current
有不同的实例。IDependency
的值为空时,我希望null
的值为LifetimeProvider.Current
。这可能吗?
P.S。以下是案例4)应该通过的测试:
[Test]
// Given There Is Lifetime Provider
// When Dependency Is Registered Per Lifetime And Lifetime Provider Becomes Null
// Then Dependency Becomes Null
public void Test()
{
var container = new SuperDuperContainer();
container.RegisterPerLifetime(
() => LifetimeProvider.Current, typeof(IDependency), null, typeof(Dependency));
var @object = string.Empty;
LifetimeProvider.Current = @object;
container.GetInstance(typeof (IDependency), null);
LifetimeProvider.Current = null;
var dependency = container.GetInstance(typeof (IDependency), null);
Assert.IsNull(dependency);
}