What are the benefits of dependency injection containers?

前端 未结 16 2775
南笙
南笙 2020-12-02 04:09

I understand benefits of dependency injection itself. Let\'s take Spring for instance. I also understand benefits of other Spring featureslike AOP, helpers of different kind

16条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 05:05

    Ease of combining partial configurations into a final complete configuration.

    For example, in web applications, the model, view and controllers are typically specified in separate configuration files. Use the declarative approach, you can load, for example:

      UI-context.xml
      Model-context.xml
      Controller-context.xml
    

    Or load with a different UI and a few extra controllers:

      AlternateUI-context.xml
      Model-context.xml
      Controller-context.xml
      ControllerAdditions-context.xml
    

    To do the same in code requires an infrastructure for combining partial configurations. Not impossible to do in code, but certainly easier to do using an IoC framework.

提交回复
热议问题