File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+
3
+ namespace Unity . Lifetime
4
+ {
5
+ /// <summary>
6
+ /// A special lifetime manager which works like <see cref="TransienLifetimeManager"/>,
7
+ /// except container remembers all Disposable objects it created. Once container
8
+ /// is disposed all these objects are disposed as well.
9
+ /// </summary>
10
+ public class ContainerControlledTransientManager : LifetimeManager
11
+ {
12
+ public override void SetValue ( object newValue , ILifetimeContainer container = null )
13
+ {
14
+ if ( newValue is IDisposable disposable )
15
+ container ? . Add ( disposable ) ;
16
+ }
17
+
18
+ public override object GetValue ( ILifetimeContainer container = null )
19
+ {
20
+ return null ;
21
+ }
22
+
23
+ public override void RemoveValue ( ILifetimeContainer container = null )
24
+ {
25
+ }
26
+
27
+ protected override LifetimeManager OnCreateLifetimeManager ( )
28
+ {
29
+ return this ;
30
+ }
31
+
32
+ public override bool InUse { get => false ; set => base . InUse = false ; }
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments