title: How should the GetService method in IDependencyResolver implementation for Unity look like?
body: <p>I'd like to use Unity as an IoC container for an ASP.NET MVC 3 app but am having trouble with my <code>UnityDependecyResolver</code> class. It currently looks like this (copied from somewhere on the web as I don't think Unity itself comes with this):</p>
  
  <pre><code>public class UnityDependencyResolver : IDependencyResolver
  {
      readonly IUnityContainer _container;
      public UnityDependencyResolver(IUnityContainer container)
      {
          this._container = container;
      }
      public object GetService(Type serviceType)
      {
          try
          {
              return _container.Resolve(serviceType);
          }
          catch
          {
              return null;
          }
      }
      public IEnumerable&lt;object&gt; GetServices(Type serviceType)
      {
          try
          {
              return _container.ResolveAll(serviceType);
          }
          catch
          {
              return new List&lt;object&gt;();
          }
      }
  }
  </code></pre>
  
  <p>However, I get this runtime error when trying to visit any controller:</p>
  
  <blockquote>
    <p>The IControllerFactory 'System.Web.Mvc.DefaultControllerFactory' did not return a controller for the name 'Account'.</p>
  </blockquote>
  
  <p><a href="http://www.thecodinghumanist.com/blog/archives/2011/1/20/structuremap-and-asp-net-mvc-3-getting-started" rel="nofollow">This StructureMap article</a> suggests that I should amend the <code>GetService</code> method, however, I'm quite new to both MVC and Unity and I'm not sure how exactly should it look like.</p>