Skip to content

Commit 97a2e29

Browse files
authored
Fixed #37
1 parent 190ec1c commit 97a2e29

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)