vendredi 8 janvier 2016

Repository pattern, object assigned to different DbContexts

I have many repositories each with own injected DbContext.

I tried to use injected by constructor Singleton DbContext and it worked but I also started to get randomly thrown database connection errors.

Is there other solution that maintains this clean code structure?

class Service : IService
{
  public void Assign(int projectId, int userId)
  {
    var project = _projectRepository.GetProject(projectId);
    var user = _usersReposotory.GetUser(userId);

    project.User = user;
    _projectRepository.UpdateUser(user);

    // Here throws error because user is attached to different _usersReposotory DbContex 
    _projectRepository.Save();
  }

}

Aucun commentaire:

Enregistrer un commentaire