title: Appropriate Repository LifeCycle Scope w/ Ninject in MVC
body: <p>What is the appropriate LifeCycle Scope for a repository and the EF context when using Entity Framework 4 with Ninject in an MVC 3 application?</p>
  
  <p>I've been using the default of InTransientScope, but questioning whether it should be InRequestScope. </p>
  
  <pre><code> public class MyController: Controller
   {
     private readonly IMyRepo _repo;
     public MyController(IMyRepo repo)
     {
       _repo = repo;
     }
  
     public ActionResult Index()
     {
       var results = _repo.GetStuff();
       return View(results);
     }
   }
  </code></pre>
  
  <p>Ninject Module:</p>
  
  <pre><code>  public class MyServices : NinjectModule
    {
      public overrride void Load()
      {
        Bind&lt;IMyRepo&gt;.To&lt;MyRepo&gt;();
        Bind&lt;MyContext&gt;.ToSelf();
      }
    }
  </code></pre>
  
  <p>MyRepo:</p>
  
  <pre><code>public class MyRepo: IMyRepo
  {
    private readonly MyContext _context;
    public MyRepo(MyContext context)
    {
      _context = context;
    }
    public IEnumerable GetStuff()
    {
      return _context.Entity;//query stuff
    }
  
  }
  </code></pre>