Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 4
    -1 for putting DbContext into a controller rather than a repo. The repo is meant to manage data providers so nobody else has to in the event a data provider changes (from MySQL to flat JSON files for instance, change in one place) Commented Jan 8, 2016 at 19:30
  • @JimmyHoffa: I'm actually looking back at the code I've written, and to be honest, I create a "context" object for my repositories, not necessary the database. I think DbContext is a bad name in this case. I'll change that. I use NHibernate, and the repositories (or context if it's handy) manage the database end of things, so changing persistence mechanisms doesn't require code changes outside the context. Commented Jan 8, 2016 at 19:36
  • you seem to be confusing controller with repository by the looks of your code... I mean, your "context" is all wrong and should absolutely not exist in the controller. Commented Jan 8, 2016 at 19:58
  • 7
    I don't have to answer and I'm not sure this is a good question to begin with, but I down vote because I think your approach is bad design. No hard feelings, I just discourage contexts being owned by controllers. IMO a controller shouldn't be starting and committing transactions like this. That's the job of any number of other places, I prefer controllers to delegate everything that's not simply fulfilling the HTTP request to somewhere else. Commented Jan 8, 2016 at 20:29
  • 1
    A repository, it's typically responsible for all data context information to ensure that nothing else needs to know anything about data concerns other than what the domain itself needs to know of Commented Jan 8, 2016 at 23:39