Inversion of Control < Dependency Injection
I'm getting the feeling that there's is not such thing as inversion of control or rather the correct term is dependency injection. Am I wrong to assume this?
I've been trying to define IoC for my own sake. In doing so I've learned a great deal about IoC containers and dependency injection.
Just now, I read this from Martin Fowler's website:
As a result I think we need a more specific name for this pattern. Inversion of Control is too generic a term, and thus people find it confusing. As a result with a lot of discussion with various IoC advocates we settled on the name Dependency Injection.
In the world of modern IoC isn't dependency injection just one way to achieve IoC?
If you accept Fowler's definition, Inversion of Control is a much broader term than DI that covers all framework usage where you plug into a framework, but the framework is still in control.
For example, in .NET, frameworks such as ASP.NET or Windows Presentation Foundation are ultimately in control, but provide various events and Seams you can use to build an application. The same is true on other platforms.
Dependency Injection is a specialization of IoC that applies IoC specifically to manage dependencies.
That's one of the few points me and Mark disagree on. By my book, Inversion of Control principle is same as here so I won't rehash it.
Dependency injection is merely an act of externalizing creation of dependencies to the outside world by components.
Managing these dependencies (and lots of other stuff) is what Inversion of Control Containers do, and using DI as part of it, is merely an implementation detail.
Yes, IoC means the class itself does not control things, but is called from outside. Dependency injection is the way to do this.
Dependency injection is indeed a much more concrete term, more well-defined than inversion of control.
链接地址: http://www.djcxy.com/p/30214.html上一篇: 控制的依赖注入和反转
下一篇: 控制反转<依赖注入