Difference between framework and container?

2019-04-17 00:23发布

I was reading this question on SO: Framework vs. Toolkit vs. Library where is explained difference between framework and library. General opinion is that main difference is in Inversion of Control, so you have hot spots in framework where you attach your application functionality (in essence you choose between inheritance/template/heavyweight or composition/strategy/lightweight to achieve that).

Ok, now I am curious what is difference between framework and container then? I saw following definition of container (by Rod Johnson): "Container is framework in which application code/objects runs". And that is what confused me. I thought that it is more or less definition of any framework :) I mean, if you use IoC as parameter that makes difference between library and framework (aka you call library, but framework calls you), then doesn't it mean that more or less any framework satisfy above definition of container?

Thanks in advance.

1条回答
不美不萌又怎样
2楼-- · 2019-04-17 01:01

I think you are mixing up the principle of Inversion of Control and an IoC tool.

The main characteristic of a framework is that it follows the IoC principle and calls your code (as explained in the linked thread). An IoC container is merely a tool, not a fullblown framework, to aid you to write cohesive, loosely coupled code following the IoC principle.

In general (at least in .Net) a class Container underlies this tool where the registration/resolving/building up object graph etc. takes place but i believe the name is an historical artifact based on the name PicoContainer and Martin Fowlers article Inversion of Control Containers and the Dependency Injection pattern.

查看更多
登录 后发表回答