title: Unity: Cannot register type from different assembly
body: <p>I'm trying to implement <code>Dependency injection</code> in my MVC application. I'm using <code>Unity.Mvc3.dll</code> for IoC. I just wondering how the Unity can't register Types from another assembly. Here's the code:</p>
  
  <pre><code>protected void Application_Start()
  {
      AreaRegistration.RegisterAllAreas();
  
      RegisterGlobalFilters(GlobalFilters.Filters);
      RegisterRoutes(RouteTable.Routes);
  
      var container = new UnityContainer();
  
      // ok: register type from this assembly
      container.RegisterType&lt;IMessages, Messages&gt;();
  
      // fail: register type from another assembly (service reference)
      container.RegisterType&lt;IPlayerService, PlayerService&gt;();
  
      DependencyResolver.SetResolver(new UnityDependencyResolver(container));
  }
  
  public class UnityDependencyResolver : IDependencyResolver
  {
      private readonly IUnityContainer _container;
  
      public UnityDependencyResolver(IUnityContainer container)
      {
          this._container = container;
      }
  
      public object GetService(Type serviceType)
      {
          try
          {
              return _container.Resolve(serviceType);
          }
          catch (Exception ex)
          {
              throw ex;
          }
      }
  
      public IEnumerable&lt;object&gt; GetServices(Type serviceType)
      {
          try
          {
              return _container.ResolveAll(serviceType);
          }
          catch (Exception ex)
          {
              throw ex;
          }
      }
  }
  </code></pre>
  
  <p>Usage in the MVC Controller:</p>
  
  <pre><code>[Dependency]
  public IPlayerService PlayerService { get; set; }
  
  [Dependency]
  public IMessages Messages { get; set; }
  
  
  public ActionResult Index()
  {
      PlayerMessageViewModel vm = new PlayerMessageViewModel();
      vm.Messages = Messages; // success!
      vm.Players = PlayerService.Get(); // fail: null reference exception :PlayerService
  
      return View(vm);
  }
  </code></pre>
  
  <p><code>PlayerService</code> is always null while the Messages is OK.</p>
  
  <p>Here is the <code>PlayerService</code> Class</p>
  
  <pre><code>public class PlayerService : IPlayerService
  {
      private readonly MyDbEntities _dbContext;
  
      public PlayerService()
      {
          _dbContext = new MyDbEntities();
      }
  
      public PlayerService(MyDbEntities dbContext)
      {
          _dbContext = dbContext;
      }
  
  
      public IQueryable&lt;Player&gt; Get()
      {
          return _dbContext.Players.AsQueryable();
      }
  }
  </code></pre>
  
  <p>this is the complete Error Message</p>
  
  <blockquote>
    <p>Resolution of the dependency failed, type = "System.Web.Mvc.IControllerFactory", name = "(none)".<br>
    Exception occurred while: while resolving.<br>
    Exception is: InvalidOperationException - The current type, System.Web.Mvc.IControllerFactory, is an interface and cannot be constructed. Are you missing a type mapping?</p>
  </blockquote>