I have started coding a small ASP.NET MVC 4 project. So far there isn't a front end, however, as I started with the API my project will expose. The API is created using Web API's API controllers. The API controllers access data stored in a Raven DB database. When debugging my code using VS 2012 and IIS Express, everything works fine. During the first request, that is. In the second request, the Raven DB IDocumentStore object (i.e. the database connection object) has been disposed and I have no idea how it happened.
I use Ninject to inject the IDocumentStore object into my repository objects and Ninject is setup like this:
public class NinjectModule: Ninject.Modules.NinjectModule {
readonly string _connStrName;
IDocumentStore _store;
public NinjectModule(string connStrName) {
_connStrName = connStrName;
}
public override void Load() {
_store = new DocumentStore { ConnectionStringName = _connStrName };
_store.Initialize();
Bind<IDocumentStore>().ToConstant(_store);
}
public override void Unload() {
_store.Dispose();
base.Unload();
}
}
The IDocumentStore is disposed in the Unload method but, as far as I can tell, the Unload method is never called.
It would be great if someone could tell me why my IDocumentStore gets disposed but I'll settle for a way to debug when it actually gets disposed. Can I trigger when a specific object is disposed?
I have checked very carefully and the IDocumentStore object is never disposed by my (still very small) code base.