Skip to content

Instantly share code, notes, and snippets.

@ardalis
Created August 28, 2014 17:19
Show Gist options
  • Save ardalis/7c93ddf2bc191d816faf to your computer and use it in GitHub Desktop.
Save ardalis/7c93ddf2bc191d816faf to your computer and use it in GitHub Desktop.
Loosely Coupled Controller Index
using System;
using System.Data.Entity;
using System.Net;
using System.Web.Mvc;
using MvcMovie.Core.Interfaces;
using MvcMovie.Infrastructure.Data;
using MvcMovie.Infrastructure.Data.Repositories;
using MvcMovie.Models;
namespace MvcMovie.Controllers
{
public class MoviesController : Controller
{
private readonly IMovieRepository _movieRepository;
private MovieDbContext db = new MovieDbContext();
public MoviesController(IMovieRepository movieRepository)
{
_movieRepository = movieRepository;
}
public MoviesController()
: this(new EfMovieRepository())
{ }
// GET: /Movies/
public ActionResult Index(string movieGenre, string searchString)
{
ViewBag.movieGenre =
new SelectList(_movieRepository.ListGenres());
return View(_movieRepository.ListMovies(movieGenre, searchString));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment