-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
|
||
namespace Unity.Lifetime | ||
{ | ||
/// <summary> | ||
/// A special lifetime manager which works like <see cref="TransienLifetimeManager"/>, | ||
/// except container remembers all Disposable objects it created. Once container | ||
/// is disposed all these objects are disposed as well. | ||
/// </summary> | ||
public class ContainerControlledTransientManager : LifetimeManager | ||
{ | ||
public override void SetValue(object newValue, ILifetimeContainer container = null) | ||
{ | ||
if (newValue is IDisposable disposable) | ||
container?.Add(disposable); | ||
} | ||
|
||
public override object GetValue(ILifetimeContainer container = null) | ||
{ | ||
return null; | ||
} | ||
|
||
public override void RemoveValue(ILifetimeContainer container = null) | ||
{ | ||
} | ||
|
||
protected override LifetimeManager OnCreateLifetimeManager() | ||
{ | ||
return this; | ||
} | ||
|
||
public override bool InUse { get => false; set => base.InUse = false; } | ||
} | ||
} |