Prism的IContainer和IUnityContainer有什么区别?

发布于 2024-07-27 03:13:56 字数 403 浏览 2 评论 0原文

我有一个 Prism 项目,其中的代码是从各种来源获得的,一切都工作得很好,但我注意到在我注入的一些模块中

IContainer container

和在其他 模块中我注入的模块

IUnityContainer container

IContainer 似乎只有组件、添加和删除,而 IUnityContainer 有数十种方法。

我经常将 IContainer 更改为 IUnityContainer,以便我可以使用后者的解析方法。 这两者之间有什么区别?为什么我要使用 IContainer?

I've got a Prism project with code that I've gotten from various sources, everything is working quite nicely, but I noticed that in some modules I inject

IContainer container

and in other modules I inject

IUnityContainer container

IContainer only seems to have Components, Add, and Remove while IUnityContainer has dozens of methods.

I'm changing IContainer to IUnityContainer often so that I can use the latter's resolve methods. What is the difference between these two and why would I want to use IContainer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任性一次 2024-08-03 03:13:56

这实际上是两个不同的东西,有着不同的目的。

IUnityContainer 是一个依赖项注入容器,它支持您在依赖项注入/服务定位场景中需要执行的所有操作,例如 BuildUp、Resolve、Register 等。您可以阅读有关 Unity 的更多信息(这实际上是 Enterprise 的一部分)库并由 CAG 使用),访问此处:Unity on Codeplex

IContainer用于为 IComponent 对象创建通用容器。 它被许多组件使用,并且位于 .NET Framework 的 System.ComponentModel 中。 它与 Unity 或 CAG 没有任何直接关系。 我认为这是更特定于 Windows 窗体而不是 WPF 的东西,尽管您可以在 WPF 中间接使用 IComponents。 IContainer

在进行任何类型的依赖项注入时,您应该使用 IUnityContainer,而不是 IContainer。

These are really two different things with different purposes.

The IUnityContainer is a dependency injection container that supports all of the things you'd need to do in a dependency injection / service location scenario, like BuildUp, Resolve, Register, etc. You can read more about Unity (which is actually part of Enterprise Library and used by the CAG) by going here: Unity on Codeplex

IContainer is used to create a generic container for objects that are IComponents. It's used by a number of components and is in the .NET Framework in System.ComponentModel. It is not related to Unity or the CAG in any direct way. I would consider this to be something that was more Windows Forms specific and less WPF, although you can use IComponents in WPF indirectly. IContainer

When doing any kind of dependency injection, you should be using IUnityContainer, not IContainer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文