title: Object disposal with dependency injection
body: <p>I have created a repository class that I want to use in a code behind page. I'm using constructor injection in the code behind page to instantiate the repository.</p>
  
  <p>Repository class:</p>
  
  <pre><code>BritanniaPremierEntities PBEntities = new BritanniaPremierEntities();
  
  public IQueryable&lt;TradeRoutes&gt; GetRoutes()
  {
      var routes = PBEntities.TradeRoutes.OrderBy(c =&gt; c.ConsignmentDate);        
  
      return routes;
  }
  
  public IQueryable&lt;TradeRoutes&gt; GetExpiredRoutes()
  {
      var routes = PBEntities.TradeRoutes.Where(
          c =&gt; c.ConsignmentDate &lt;= System.DateTime.Now);
  
      return routes;
  }
  </code></pre>
  
  <p>Code behind page</p>
  
  <pre><code>private IRepository repos;
  
  public Admin_TradeRoutesAdmin()
      : this(new Repository()) 
  {
  }
  
  public Admin_TradeRoutesAdmin(IRepository repos)
  {
      this.repos = repos;
  }
  
  public IQueryable GetTradeRoutes()
  {        
      // call repository method
      return repos.GetRoutes();
  }
  </code></pre>
  
  <p>Here is where I get a little confused. How should I ensure the repository is disposed correctly? For instance, I'm unable to wrap the repository calls in using statements in the code behind page, thus making use of the dispose method in the repository.</p>