什么是UnityContainer.Resolve超过Activator.CreateInstance的优势在哪里? [英] What is the advantage of UnityContainer.Resolve over Activator.CreateInstance?
本文介绍了什么是UnityContainer.Resolve超过Activator.CreateInstance的优势在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚开始接触团结。我仍然不知道什么其优点。
UnityContainer()解决< T>()
,可以返回
已注册为通用型的类型的具体实例 T
。
我想我也可以使用 Activator.CreateInstance< T>()
。
激活
是一个内置在.NET Framework类,所以我想知道什么样的显着特点的团结是?
解决方案
MSDN指出,这些为统一集装箱的优势:
- 简化对象的创建,特别是对于分层对象结构和依赖
- 的规定抽象;这使得开发人员能够在运行时还是在配置中指定依赖,简化横切关注点管理
- 在通过延迟组件配置到容器更大的灵活性
- 在服务定位能力;这使得客户端存储或缓存容器
- 实例和类型拦截。
这里是链接。
I'm just getting started with Unity. I am still wondering what its advantages are.
UnityContainer().Resolve<T>()
which can return
a concrete instance of the type that is registered for the generic type T
.
I think I can also use Activator.CreateInstance<T>()
.
Activator
is a built-in class in the .NET Framework, so I am wondering what the distinct feature for Unity is?
解决方案
MSDN states these as the advantages of 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.
Here's the link.
这篇关于什么是UnityContainer.Resolve超过Activator.CreateInstance的优势在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文