我应该通过IOC容器构建? [英] What should be constructed through an IOC container?

查看:117
本文介绍了我应该通过IOC容器构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何确定哪些类应通过IOC容器,哪些不应该构成。我已经在项目两个​​极端工作,好像接口,当班组长规定如日志或数据访问的特定technoliogy应该只被使用?

How do you determine which classes should be constructed through an IOC container, and which ones shouldn't. I've worked on projects with both extremes and it seems like interfaces should only be used when the classs specifies a specific technoliogy like logging or data access?

在哪里的人吸取上述两种之间的界限?

Where do people draw the line between the two?

推荐答案

我不画任何线 - 越多,越多越好

I don't draw any line - the more, the merrier.

什么情况是,你越能设法分散你的API中的小户型,越接近你到了的单一职责原则,因为一切都隐藏在接口后面将有一种倾向,只做一件事,把它做好。

What happens is that the more you can manage to split up your API in small units, the closer you get to the Single Responsibility Principle, because everything that hides behind an interface will have a tendency to do only one thing, and do it well.

通过注入接口到实现,实现新的接口被注入到其它类型的等你结束了一个非常灵活的结​​构,在那里你可以在几乎任何级别的改变实现细节,每一个合作者是pretty的简单本身。

By injecting interfaces into implementation that implement new interfaces that are injected into other types, etc. you end up with a very flexible structure where you can vary implementation details at almost any level, and each collaborator is pretty simple in itself.

有了一个良好的DI容器和一些明智的公约,DI容器将自动照顾大多数为您的布线,所以配置并不一定是极端的。

With a good DI Container and some sensible conventions, the DI Container will automatically take care of most of the wiring for you, so the configuration doesn't have to be extreme.

这篇关于我应该通过IOC容器构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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