什么时候使用IoC是合适的? [英] When is using IoC appropriate?

查看:144
本文介绍了什么时候使用IoC是合适的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解IoC容器是什么,并且已经在Structure Map上进行了阅读.该技术似乎很容易使用.我的问题是,使用IoC容器的合适的粒度级别是多少?

I understand what IoC containers are and have been reading up on Structure Map. The technology seems easy enough to use. My question is, what is the appropriate level of granularity for using an IoC container?

我看到以下IoC应用级别:

I see the following possible levels of application for IoC:

  1. 打破所有对象之间的每个依赖关系-肯定会过分杀伤.
  2. 打破所有主要对象之间的依赖关系,例如域对象,支持类和子系统内的组件.
  3. 将IoC与Facade结合使用以使用公共接口包装子系统(例如日志记录),然后打破对该接口的依赖性.

我知道此问题的答案是取决于",但是根据您的经验,答案取决于什么?项目规模是一个因素吗?

I know the answer to this question is "it depends", but from your experience, what does then answer depend on? Is project size a factor?

此外,在哪里使用IoC没有意义?

Furthermore, where doesn't IoC make sense to use?

推荐答案

这个想法不是要打破域对象之间的依赖关系,而是要保护您的域与外界隔离.您的域对象应该与您要解决的任何业务问题有关,而与数据库,日志记录,缓存,http上下文,REST服务等无关.

The idea isn't to break dependencies between domain objects, it's to shield your domain from the outside world. Your domain objects should be about whatever business problem you are solving and not about databases, logging, caching, http contexts, rest services etc...

本文讨论了将职责移出对象并移入IoC容器的情况.

This article talks about moving responsibilities out of your objects and into the IoC container.

http://www.agileatwork.com/captcha-and-控制反转/

这篇关于什么时候使用IoC是合适的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆