I have this code.
A base class that create a new instance of the context.
public class Base
{
private Entities context;
public Base()
{
context = new Entities();
}
}
And than the classes that inherit from this class.
public class SomeService : Base
{
public Gallery Get(int id)
{
return context.GallerySet.FirstOrDefault(g => g.id == id);
}
}
The question is,how to take care of disposing the context object ? I was thinking about a destructor in the base clas, where I would just call the dispose method of the context object.
~Base()
{
context.Dispose();
}
Would be this enough ? Or is there any other way to take care of the context object ?