My MVC2 application has an entity name RDDB.edmx and I created a repository object to use an an accessor by my program called RDDBDataStore. I find that I create instances of this object throughout my program but have had trouble creating instances of it with "using" statements as shown below.
1) Is there a way I can create one instance that gets used throughout my application? Could I do this in the Glaboal.asax file? One instance would solve the problem I have.
If I must create new instances of RDDBDataStore as needed:
2) Would Connection Pooling be useful to me?
The problem I have with the multiple "using" statement route is that sometimes I need a returned list to persist so that a view, for example, can display that list. When I use a "using" statement, the object is gone and I get a null pointer exception.
I need to understand the best practices solution for this, so please feel free to make suggestions.
public class RDDBDataStore : IDisposable
private RDDB entities = null;
entities = new RDDB();
public void Dispose()
using (RDDBDataStore ds = new RDDBDataStore())
// access ds here...