Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Data.Entity;
- namespace CommonLibrary.Database
- {
- public abstract class DbContextLocator<TContext> where TContext : DbContext, new()
- {
- private TContext _dbContext;
- public TContext Current
- {
- get { return _dbContext; }
- }
- public DbContextLocator()
- {
- _dbContext = GetNew();
- }
- public virtual void Reset()
- {
- _dbContext.Dispose();
- _dbContext = GetNew();
- }
- protected virtual TContext GetNew()
- {
- return Activator.CreateInstance<TContext>();
- }
- }
- }
- //Concrete class
- using System.Data.Entity;
- using CommonLibrary.Database;
- using ExperimentBase.EntityModels;
- namespace MainProject.Models
- {
- public class MainDbContextLocator : DbContextLocator<MainDbContext> { }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement