I want to dispose the devDB context object in the below code.
private static void InitContainer()
{
var devDB = new TestContext(constr);
Container
.RegisterInstance<TestContext>(devDB)
.RegisterInstance<IRepository<User>>(new Repository<User>(devDB))
}
private static void CleanUp()
{
if (Container != null)
{
Container.Dispose();
}
}
I tried a using statement, but the I receive the following error:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
How can I dispose devDB correctly?
Pravesh Singh
23-Jan-2014Use using statements:
It will automatically Dispose your variable if it's Disposable.