Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 695
Adam Lee Avatar asked Oct 07 '22 12:10

Adam Lee


1 Answers

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.

like image 52
SuperPrograman Avatar answered Nov 05 '22 20:11

SuperPrograman