我刚刚开始使用 Unity。我还在想它的优点是什么。
UnityContainer().Resolve<T>()
哪个可以返回
为通用类型注册的类型的具体实例 T
.
我想我也可以使用 Activator.CreateInstance<T>()
.
Activator
是 .NET Framework 中的内置类,所以我想知道 Unity 的独特功能是什么?
最佳答案
MSDN 指出这些是 Unity Container 的优势:
- Simplified object creation, especially for hierarchical object structures and dependencies
- Abstraction of requirements; this allows developers to specify dependencies at run time or in configuration and simplify management of crosscutting concerns
- Increased flexibility by deferring component configuration to the container
- Service location capability; this allows clients to store or cache the container
- Instance and type interception.
这是 link .
关于c# - UnityContainer.Resolve 比 Activator.CreateInstance 有什么优势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11075574/