Usage of IoC Containers; specifically Windsor

后端 未结 5 1868
孤独总比滥情好
孤独总比滥情好 2020-11-29 04:07

I think the answer to this question is so obivous that noone has bothered writing about this, but its late and I really can\'t get my head around this.

I\'ve been re

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 04:34

    As the other answers here state there are a lot of choices, and again we're left to ourselves to figure out what is best in our case.

    That said, IMO having a global container that is accessed throughout your application somewhat breaks isolation in that a lot of code now depends on the one global class. Also, for applications that is split out into several assemblies, the global container must be made accessible to all these assemblies.

    With Unity you can actually have a IUnityContainer parameter in your constructor and the container will automatically inject itself into the instance when you resolve the class. This way, for services that needs to resolve other services you pass in the container instead of forcing the class to reference the external class.

    Not sure how other frameworks support this scenario (Windsor will inject IKernel).

提交回复
热议问题