1
我对AutoFac只有非常熟悉,并且我询问下面详细描述的功能是否可用,并且它看起来“不完全”。你知道这是可能的容器吗?允许删除注册的.NET IOC容器
[TestFixture]
public class SomeCunningTests
{
class SomeType { }
[Test]
public void TestRegistrationScope()
{
var container = new IocContainerOfSomeKind();
using (new RegistrationScope(container, new SomeType()))
{
Assert.IsTrue(container.IsRegistered(typeof(SomeType)));
}
Assert.IsFalse(container.IsRegistered(typeof(SomeType)));
}
public class RegistrationScope<T> : IDisposable
{
public RegistrationScope(IocContainerOfSomeKind container, T instance)
{
//code here for registering instance
}
public void Dispose()
{
//unregister instance somehow
}
}
}