@@ -6,7 +6,7 @@ namespace Unity.Lifetime
6
6
/// A <see cref="LifetimeManager"/> that holds a weak reference to
7
7
/// it's managed instance.
8
8
/// </summary>
9
- public class ExternallyControlledLifetimeManager : LifetimeManager ,
9
+ public class ExternallyControlledLifetimeManager : SynchronizedLifetimeManager ,
10
10
IInstanceLifetimeManager ,
11
11
ITypeLifetimeManager ,
12
12
IFactoryLifetimeManager
@@ -18,35 +18,36 @@ public class ExternallyControlledLifetimeManager : LifetimeManager,
18
18
#endregion
19
19
20
20
21
- #region Overrides
21
+ #region SynchronizedLifetimeManager
22
22
23
- /// <summary>
24
- /// Retrieve a value from the backing store associated with this Lifetime policy.
25
- /// </summary>
26
- /// <param name="container">Instance of container requesting the value</param>
27
- /// <returns>the object desired, or null if no such object is currently stored.</returns>
28
- public override object GetValue ( ILifetimeContainer container = null )
23
+ /// <inheritdoc/>
24
+ protected override object SynchronizedGetValue ( ILifetimeContainer container = null )
29
25
{
30
26
if ( null == _value ) return NoValue ;
31
27
32
28
var target = _value . Target ;
33
- if ( _value . IsAlive ) return target ;
29
+ if ( null != target ) return target ;
34
30
35
31
_value = null ;
36
32
37
33
return NoValue ;
38
34
}
39
35
40
- /// <summary>
41
- /// Stores the given value into backing store for retrieval later.
42
- /// </summary>
43
- /// <param name="container">Instance of container which owns the value</param>
44
- /// <param name="newValue">The object being stored.</param>
45
- public override void SetValue ( object newValue , ILifetimeContainer container = null )
36
+ /// <inheritdoc/>
37
+ protected override void SynchronizedSetValue ( object newValue , ILifetimeContainer container = null )
46
38
{
47
39
_value = new WeakReference ( newValue ) ;
48
40
}
49
41
42
+
43
+ /// <inheritdoc/>
44
+ public override void RemoveValue ( ILifetimeContainer container = null ) => _value = null ;
45
+
46
+ #endregion
47
+
48
+
49
+ #region Overrides
50
+
50
51
protected override LifetimeManager OnCreateLifetimeManager ( )
51
52
{
52
53
return new ExternallyControlledLifetimeManager ( ) ;
0 commit comments