title: Using IoC in extension methods
body: <p>I am working on an ASP MVC 3 app and I'm writing a custom html helper. It's nothing special or hugely complex, but it will need an instance of an interface from structure map. I know I can simply call into structuremaps' object factory from inside the method, but since the rest of the app uses IoC rather than service location I'd like to keep it that way.</p>
  
  <p>Is there a way to inject interfaces into extension methods from inside and asp net mvc app?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>An example of what I'm doing might help:</p>
  
  <pre><code>public static class ShowUrl
  {
      public static string ForShow(this UrlHelper url, int showId)
      {
          var service = ObjectFactory.GetInstance&lt;IPerformanceService&gt;();
  
          var showName = service.GetPerformanceTitle(showId);
  
          return url.Action(MVC.Performance.Details(showId, showName.ToFriendlyUrl()));
      }
  }
  </code></pre>
  
  <p>Which is used like this:</p>
  
  <pre><code>&lt;a href='&lt;%= Url.ForShow(1)%&gt;'&gt;
  </code></pre>
  
  <p>Essentially I am trying to build a URL with a slug from an entity id. Maybe I'm just going about this in a really daft way. </p>