Files
TheXamlGuy/Framework/Core/LifeCycles/Scope.cs
T
2022-11-01 15:26:08 +00:00

23 lines
674 B
C#

using System;
using System.Collections.Concurrent;
using System.Reactive.Disposables;
namespace TheXamlGuy.Framework.Core
{
public class Scope : IScope
{
private readonly ConcurrentDictionary<object, bool> scopes = new ConcurrentDictionary<object, bool>();
public IDisposable Enter<T>(object target)
{
scopes.TryAdd(Tuple.Create(target, typeof(T)), true);
return Disposable.Create(() => scopes.TryRemove(Tuple.Create(target, typeof(T)), out bool value));
}
public bool IsActive<T>(object target)
{
return scopes.ContainsKey(Tuple.Create(target, typeof(T)));
}
}
}