I wanted to try to expose a DbContext instance through a get statement:
public class SomeContext : DbContext
{
public SomeContext()
{
}
public DbSet<SomeModel1> SomeModel1s { get; set; }
public DbSet<SomeModel2> SomeModel2s { get; set; }
//etc
}
public class SomeInterfaceImplementation
{
SomeContext ContextInstance { get; }
//etc
}
But instead of using ContextInstance as a singleton, I want to do something so that calling ContextInstance actually does something like:
someVar = ContextInstance.SomeModel1s.Where(x => x.SomeID == externalID).OrderBy(x => x.SomeProperty).ToList();
//becomes the same as
using (var db = new SomeContext())
{
someVar = db.SomeModel1s.Where(x => x.SomeID == externalID).OrderBy(x => x.SomeProperty).ToList();
}
basically, I just want to hide the using statement and create and dispose an instance of SomeContext every time ContextInstance is called. Hopefully I make sense. Does anyone have something in mind to do this?