I'm trying to figure out how the kernel disposed of objects it has in it. For example, the following code creates two scopes and asserts that the same object is resolves when the scope if the same, a different one when it's different.
[Test]
public void DisposingScope()
{
var kernel = new StandardKernel();
ScopeObject scopeObject = null;
kernel.Bind<IBall>().To<RedBall>().InScope(context => scopeObject);
var scope1 = new ScopeObject();
var scope2 = new ScopeObject();
scopeObject = scope1;
var ball1A = kernel.Get<IBall>();
var ball1B = kernel.Get<IBall>();
Assert.That(ball1A, Is.SameAs(ball1B)); // <== Balls from the same scope
scopeObject = scope2;
var ball2 = kernel.Get<IBall>();
Assert.That(ball2, Is.Not.SameAs(ball1A)); // <== Balls from different scopes
}
As I have two scopes, there are two instances of RedBall
held in the container.
- How\when do these get removed?
- How can I extend my test to prove that the balls in the container are disposed?