-
Notifications
You must be signed in to change notification settings - Fork 60
Description
Background and Motivation
Again lifetimes is awesome so i integrated that everywhere and i have activatable view models. Basicaly its same aproach but to force deactivate view. And I came across that in some places I would like to use same view model so i want deactivate that only when no one use this.
public interface IActivatableViewModel
{
public void Activate(Lifetime lifetime);
}2nd example
I have gpsService which track location and i want to stop tracking only when no one use this
public interface IGpsLocation
{
public IObservable<Location> TrackLocation(Lifetime lifetime);
}Proposed API
In order to provide a way to dispose that definition need to create spicific definition
public class UnionLifetimeDefinition(Lifetime parentLifetime)
{
public Lifetime Lifetime { get; }
public void Add(Lifetemi lifetime);
}Alternative Designs
I thought about same approach like with Intersection, but its not good due to the fact that will not have a way to terminate that. Smth like add method Union and DefineUnion to lifetime. Basicaly same stracture as with Intersection
public Lifetime Union(Lifetime other) => Union(this, other);
public static Lifetime Union(params Lifetime[] lifetimes);
public static LifetimeDefinition DefineUnion(params Lifetime[] lifetimes);but it not possible to terminate same way, for intersection its possible to use global lifetime in the same place
var lf = Lifetime.Intersection(globalLifetime, localLifetime1, localLifetime2);