diff --git a/package.props b/package.props index 043c9be6..b82659e3 100644 --- a/package.props +++ b/package.props @@ -1,7 +1,7 @@ - 5.11.2 + 5.11.3 netstandard2.0;netstandard1.0;netcoreapp2.0;netcoreapp1.0;net47;net46;net45;net40 diff --git a/src/Lifetime/Managers/ExternallyControlledLifetimeManager.cs b/src/Lifetime/Managers/ExternallyControlledLifetimeManager.cs index b3187ddb..8647e0f7 100644 --- a/src/Lifetime/Managers/ExternallyControlledLifetimeManager.cs +++ b/src/Lifetime/Managers/ExternallyControlledLifetimeManager.cs @@ -6,7 +6,7 @@ namespace Unity.Lifetime /// A that holds a weak reference to /// it's managed instance. /// - public class ExternallyControlledLifetimeManager : LifetimeManager, + public class ExternallyControlledLifetimeManager : SynchronizedLifetimeManager, IInstanceLifetimeManager, ITypeLifetimeManager, IFactoryLifetimeManager @@ -18,35 +18,36 @@ public class ExternallyControlledLifetimeManager : LifetimeManager, #endregion - #region Overrides + #region SynchronizedLifetimeManager - /// - /// Retrieve a value from the backing store associated with this Lifetime policy. - /// - /// Instance of container requesting the value - /// the object desired, or null if no such object is currently stored. - public override object GetValue(ILifetimeContainer container = null) + /// + protected override object SynchronizedGetValue(ILifetimeContainer container = null) { if (null == _value) return NoValue; var target = _value.Target; - if (_value.IsAlive) return target; + if (null != target) return target; _value = null; return NoValue; } - /// - /// Stores the given value into backing store for retrieval later. - /// - /// Instance of container which owns the value - /// The object being stored. - public override void SetValue(object newValue, ILifetimeContainer container = null) + /// + protected override void SynchronizedSetValue(object newValue, ILifetimeContainer container = null) { _value = new WeakReference(newValue); } + + /// + public override void RemoveValue(ILifetimeContainer container = null) => _value = null; + + #endregion + + + #region Overrides + protected override LifetimeManager OnCreateLifetimeManager() { return new ExternallyControlledLifetimeManager(); diff --git a/src/Unity.Abstractions.csproj b/src/Unity.Abstractions.csproj index fa3864a3..b6e51a12 100644 --- a/src/Unity.Abstractions.csproj +++ b/src/Unity.Abstractions.csproj @@ -63,7 +63,7 @@ - + all runtime; build; native; contentfiles; analyzers