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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top