Can anyone explain to me, at length, how to use IOC containers?

后端 未结 7 1730
执笔经年
执笔经年 2021-02-05 15:47

I use dependency injection through parameters and constructors extensively. I understand the principle to this degree and am happy with it. On my large projects, I end up with t

7条回答
  •  梦如初夏
    2021-02-05 16:37

    I have no links but can provide you with an example:

    You have a web controller that needs to call a service which has a data access layer.

    Now, I take it in your code you are constructing these objects your self at compile time. You are using a decent design pattern, but if you ever need to change the implementation of say the dao, you have to go into you code and remove the code that sets this dependency up, recompile / test/ deploy. But if you were to use a IOC container you would just change the class in the configuration and restart the application.

提交回复
热议问题