Skip to content

Instantly share code, notes, and snippets.

@yemrekeskin
Last active December 15, 2015 22:19
Show Gist options
  • Save yemrekeskin/5331948 to your computer and use it in GitHub Desktop.
Save yemrekeskin/5331948 to your computer and use it in GitHub Desktop.
Using Context Factory
public interface IContextFactory
{
SampleContext GetContext();
}
public class ContextFactory
:IContextFactory,IDisposable
{
private SampleContext _sampleContext;
public SampleContext GetContext()
{
return _sampleContext ?? (_sampleContext = new SampleContext());
}
public void Dispose()
{
if (null != _sampleContext)
_sampleContext.Dispose();
}
}
public class SampleContext
:DbContext
{
public DbSet<Category> Category { get; set; }
public SampleContext(string contextName)
:base(contextName)
{
}
public SampleContext()
:base("")
{
}
public void Commit()
{
base.SaveChanges();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment