Injecting the context
Last updated
Last updated
Open the Controllers/MoviesController.cs
file and inject the context as shown
The constructor, with the help of Dependency Injection, receives an object of MvcMovieContext
. The database context is used in each of the CRUD methods in the controller.
Using the same technique of dependency injection, we can inject any other service into any controller which requires it, thereby keeping the usage and implementation separate we will look at other uses of dependency injection later.