Why When use IoC in MVC Application?

This question already has an answer here:

  • Why do I need an IoC container as opposed to straightforward DI code? [closed] 30 answers
  • What is dependency injection? 31 answers


  • Bacause it is a good practice. Code is much clearer and easier to maintenance.
  • For example i'm using it in controllers constructors (i pass repositories and services as arguments) and in repositories (i pass dbcontext as argument) - but it depends on your project's architecture.
  • StructureMap is one of the Ioc containers (i personally prefer NInject or Funq) so without it you miss all advantages of using IoC.
  • 链接地址: http://www.djcxy.com/p/14414.html

    上一篇: PHP中接口和抽象类的重要性

    下一篇: 为什么在MVC应用程序中使用IoC?