Difference IoC container and Factory pattern

   1 I would suggest to keep the concepts plain and simple. Dependency Injection is more of a architectural pattern for loosely coupling software components. Factory pattern is just one way to separate the responsibility of creating objects of other classes to another entity. Factory pattern can be called as a tool to implement DI. Dependency injection can be implemented in many ways like DI using constructors, using mapping xml files etc.


    2 Inversion of Control (IoC) and Dependency Injection (DI) usually refer to the same thing. IoC is a more general concept (instead of doing X itself, a class relies on some other class to do it) DI is IoC as applied to dependent classes (instead of creating a class that I depend on, it will be passed to me). DI is the most common use of IoC, so usually when they are discussed the terms are used interchangeably.


The Factory Pattern's main concern is creating things - DI's main concern is how things are connected together.

In practice, these two concerns (creating and connecting) are usually related, so most DI/IoC containers do both. You could think of most implementations as very configurable factories - but because the implementations address both concerns - not because the Factory pattern and DI/IoC are the same.

阅读更多
文章标签: ioc containers class xml
上一篇Understanding the DIP, DI, IoC theory
下一篇Inversion of Control – An Introduction with Examples in .NET
想对作者说点什么? 我来说一句

工厂类模型 应用

2014年02月22日 3.36MB 下载

Unity Ioc Container 实例

2015年02月06日 664KB 下载

没有更多推荐了,返回首页

关闭
关闭