I\'m using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. F
In addition to the standard scopes of Transient, OnePerThread, and Singleton, you can use an ActivationBlock in order to control the lifetime of a whole set of objects. When the block is disposed, all object retrieved by the block go out of scope - so singletons and others are disposed of when their instances are requested by the activation block.
var kernel = new StandardKernel();
kernel.Bind().ToSelf();
NotifiesWhenDisposed instance = null;
using(var block = new ActivationBlock(kernel))
{
instance = block.Get();
instance.IsDisposed.ShouldBeFalse();
}
instance.IsDisposed.ShouldBeTrue();