title: Dependency Injection when controller called from another controller
body: <p>I have a single ASP.NET 5.0 (vnext) project where I am implementing both a Web Api and an Mvc front end. I want my Mvc controller to call the Web Api controller, which is working just fine. I built the api based on the example at <a href="http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6" rel="nofollow">http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6</a>, and it is working great. The Mvc front end can call the WebApi controller successfully, but the ITodoRepository doesn't get provided by the dependency injection framework when I instantiate it from the Mvc controller.</p>
  
  <pre><code>public class Startup
  {
      public void Configure(IApplicationBuilder app, ILoggerFactory logFactory)
      {
          ...
          app.UseServices(services =&gt;
          {
              services.AddSingleton&lt;ITodoRepository, TodoRepository&gt;();
          });
          ...
  
  [Route("api/[controller]")]
  public class TodoController : Controller
  {
      /* The ITodoRepository gets created and injected, but only when the class is activated by Mvc */
      TodoController(ITodoRepository repository)
      {
          _repository = repository;
      }
  
      [HttpGet]
      public IEnumerable&lt;TodoItem&gt; Get()
      {
          return _repository.AllItems;
      }
      ...
  
  public class HomeController : Controller
  {
      public IActionResult Index()
      {
          var tc = new TodoController(/* have to create my own ITodoRepository here */);
          return View(tc.Get());
      }
      ...
  </code></pre>
  
  <p>I was able to add an ITodoRepository to the HomeController with the [Activate] attribute, and then pass that to the constructor for the TodoController, but that doesn't pass the smell test to me. Home Controller shouldn't have to have or even know about those.</p>
  
  <p>Is there another way to create the TodoController instance that will invoke the DI logic and provide the dependencies?</p>