Domanda

I have repository with constructor which looks like

public Repository(ObjectContext context)
{
    _context = context;
    _objectSet = _context.CreateObjectSet<T>();
}

I use Ninject in my MVC app to bind ObjectContext like this

var connectionString = ConfigurationManager.ConnectionStrings["Entities"].ConnectionString;    
kernel.Bind(typeof(ObjectContext)).ToMethod(context => new Entities(connectionString)).InSingletonScope();

I am not sure about InSingletonScope in this case. Should I use it or not?

È stato utile?

Soluzione

Almost certainly not, you want to make sure that each repository is separate and for example a call to savechanges on one will not commit things from another repository.

I would also recommend using DbContext instead of ObjectContext.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top