Skip to content

Commit

Permalink
Fixed #37
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS authored Jan 23, 2018
1 parent 190ec1c commit 97a2e29
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Lifetime/ContainerControlledTransientManager.cs
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; }
}
}

0 comments on commit 97a2e29

Please sign in to comment.