title: IoC in MVC: How do I handle the flow of service objects from controllers through models?
body: <p>I am using MVC3 and have implemented IoC to provide service/manager objects to controllers through constructor arguments. These in turn, may get passed to models.</p>
  
  <p>The problem I am having is that passing these objects all over the place can get cumbersome.</p>
  
  <p>Example:</p>
  
  <pre><code>public CartController(
          ICartManager cartManager,
          IProductManager productManager,
          IUpsellManager upsellManager,
          IAccountManager accountManager,
          ... more ...)
      {
          ... store to class variables ...
      }
  
      public ActionResult Index()
      {
          ...
  
          CartModel model = new CartModel(
              cartManager, 
              accountManager, 
              upsellManager, 
              productManager, 
              ... );
  
          return View(model);
      }
  </code></pre>
  
  <p>And the cart model may have sub models to which it must pass parameters. As you see, it all gets very cumbersome. I've ready if you have so many constructor arguments, your controller may be doing too much, but this is a complex page, and the site will contain many other complex pages. I don't want to have to pass so many things, but how can I not pass them and maintain a control?</p>
  
  <p>I'm tempted to use the DependencyResolver in the models but that defeats the purpose and Service Locator is known anti-pattern.</p>
  
  <p>How can I avoid passing so many arguments without giving up the benefits of IoC?</p>