What is the advantage of UnityContainer.Resolve over Activator.CreateInstance?

折月煮酒 提交于 2019-12-22 05:53:08

问题


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?


回答1:


MSDN states these as the advantages of 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.

Here's the link.



来源:https://stackoverflow.com/questions/11075574/what-is-the-advantage-of-unitycontainer-resolve-over-activator-createinstance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!