c# - UnityContainer.Resolve 比 Activator.CreateInstance 有什么优势?

标签 c# .net unity-container activator

我刚刚开始使用 Unity。我还在想它的优点是什么。

UnityContainer().Resolve<T>()哪个可以返回 为通用类型注册的类型的具体实例 T .

我想我也可以使用 Activator.CreateInstance<T>() .

Activator是 .NET Framework 中的内置类,所以我想知道 Unity 的独特功能是什么?

最佳答案

MSDN 指出这些是 Unity Container 的优势:

  1. Simplified object creation, especially for hierarchical object structures and dependencies
  2. Abstraction of requirements; this allows developers to specify dependencies at run time or in configuration and simplify management of crosscutting concerns
  3. Increased flexibility by deferring component configuration to the container
  4. Service location capability; this allows clients to store or cache the container
  5. Instance and type interception.

这是 link .

关于c# - UnityContainer.Resolve 比 Activator.CreateInstance 有什么优势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11075574/

相关文章:

c# - 更改在 .Net 中序列化的类的名称?

c# - 使用私钥签署程序集

c# - 在 C# 中,我如何像 google calc 那样实现模数?

c# - 不用 goto 编写重试逻辑的更好方法

c# - 为什么推荐的 dispose 模式会在层次结构的每个级别添加一个已处理字段?

c# - Unity(依赖注入(inject)): How to pass in a parameter to the constructor in RegisterType

c# - 使用自定义 HResult 抛出ExternalException

.net - .NET 的 SabreDAV?

dependency-injection - 自定义成员(member)提供者和 Unity 注入(inject)

unity-container - 如何注册实现相同接口(interface)的多个类型