IOC容器的最佳做法 [英] Best Practices for IOC Container

查看:63
本文介绍了IOC容器的最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Unity IOC容器,我只是想知道什么是访问多个类的容器的最佳方法.

I'm using the Unity IOC container and I'm just wondering what is the best best way to access the container for multiple classes.

每个类都应该有一个IUnityContainer成员,然后通过构造函数将容器传递进来吗?应该有一个带有IOC容器的单例课程吗?

Should every class have an IUnityContainer member and then pass the container in by constructor? Should there be a singleton class with an IOC container?

asp.net开发如何?

How about asp.net development?

有人可以指引我正确的方向吗?谢谢.

Could somebody guide me in the right direction? Thanks.

推荐答案

将IOC容器放在流程的最高级别/入口点,并使用它在其下的所有内容中注入依赖项.

Put the IOC container at the highest level / entry point in the process and use it to inject dependencies in everything underneath it.

这篇关于IOC容器的最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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