Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you force Unity to Create a new instance?

Using Unity Application block how can you force the Unity configuration to create a new instance of an object when we call the UnityContainer.Resolve<T>() method in WCF context?

like image 524
Andy Clark Avatar asked Aug 21 '12 14:08

Andy Clark


1 Answers

Using RegisterType without a LifetimeManager should inject a new instance of the type every time it is injected

From MSDN:

If you do not specify a value for the lifetime, the type is registered for a transient lifetime, which means that a new instance will be created on each call to Resolve

like image 163
StuartLC Avatar answered Oct 19 '22 23:10

StuartLC