Ich kenne AutoFac nur sehr gut, und ich fragte, ob das unten beschriebene Feature damit möglich sei, und es schien "nicht genau". Kennst du einen Container mit dem dies möglich wäre?.NET IOC-Container, der das Entfernen von Registrierungen ermöglicht
[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
}
}
}