Unity Lifetime Manager is all you need. By default, Unity uses the TransientLifetimeManager :
TransientLifetimeManager. For this time manager, Unity creates and returns a new instance of the requested type for each call to the Resolve or ResolveAll method. This lifetime manager is used by default for all types registered using the RegisterType method, unless you specify another life manager.
If you need to use another lifetime manager, simply specify in the Register method:
var container = new UnityContainer(); container.RegisterType<IMyType, MyType>(new PerResolveLifetimeManager());
Cuong le
source share