You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every lifetime manager implementing IDisposable must be added to the container's scope to be disposed when that scope goes away or being disposed manually. In cases when object held by the manager is not IDisposable the manager would be held by the lifetime container for no good reason.
This implementation was mandated by the original API where LefetimeManager.SetValue(object value) had only one parameter for the value itself.
Solution
Unity v5 introduced new API: LefetimeManager.SetValue(object value, ILifetimeContainer scope).
This new API allowed to add objects to the scope on demand and in case of ContainerControlledTransientManager multiple objects when resolved.
With addition of this new API the SynchronizedLifetimeManager was still derived from IDisposable and was held in scope collection. This added unnecessary iterations during disposal as well as disposed some objects more than once.
Unity v6 removes IDisposable from SynchronizedLifetimeManager and deprecated ILifetimeContainer interface so these issues are no longer contribute to overhead.
SetValue API
Starting with Unity v6, the new API is as follows:
Custom managers derived from SynchronizedLifetimeManager must no longer rely on framework to be added to scope collection. If custom manager must implement IDisposable and be disposed during scope destruction, the manager must implement IDisposable and add itself to the scope during SetValue(...) call.
The text was updated successfully, but these errors were encountered:
IDisposable implementation
Unity v4 and v5 declared
SynchronizedLifetimeManager
as follows:Problem
Every lifetime manager implementing
IDisposable
must be added to the container's scope to be disposed when that scope goes away or being disposed manually. In cases when object held by the manager is notIDisposable
the manager would be held by the lifetime container for no good reason.This implementation was mandated by the original API where
LefetimeManager.SetValue(object value)
had only one parameter for the value itself.Solution
Unity v5 introduced new API:
LefetimeManager.SetValue(object value, ILifetimeContainer scope)
.This new API allowed to add objects to the scope on demand and in case of
ContainerControlledTransientManager
multiple objects when resolved.With addition of this new API the
SynchronizedLifetimeManager
was still derived fromIDisposable
and was held in scope collection. This added unnecessary iterations during disposal as well as disposed some objects more than once.Unity v6 removes
IDisposable
fromSynchronizedLifetimeManager
and deprecated ILifetimeContainer interface so these issues are no longer contribute to overhead.SetValue API
Starting with Unity v6, the new API is as follows:
Impact
Custom managers derived from
SynchronizedLifetimeManager
must no longer rely on framework to be added to scope collection. If custom manager must implementIDisposable
and be disposed during scope destruction, the manager must implementIDisposable
and add itself to the scope duringSetValue(...)
call.The text was updated successfully, but these errors were encountered: