Welcome to the Treehouse Community
Looking to learn something new?
Why don't we call directly to the repository Get.. functions?
Instead of creating an instance of the context in the controller and paste the queries inside the controller, why don't we call directly the get methods located in the repository class from the controller? Is it because there the context is closed and then it will give an object disposition exception? Thanks
James ChurchillTreehouse Teacher
Calling the methods on the existing Repository class shouldn't throw an exception (you could test this and see if that's the case or not). The reason that we're not using the existing Repository class is that each of its methods instantiates its own instance of the Context class, which is less than ideal for an MVC application.
For a discussion on this issue, see this video: https://teamtreehouse.com/library/preparing-our-plan