Beispiel #1
0
        /// <summary>
        /// Creates a disposable subscription to the lifecycle.
        /// </summary>
        /// <param name="observable">The lifecycle observable.</param>
        /// <param name="observerName">The name of the observer.</param>
        /// <param name="stage">The stage to participate in.</param>
        /// <param name="onStart">The delegate called when starting the specified lifecycle stage.</param>
        /// <param name="onStop">Teh delegate to be called when stopping the specified lifecycle stage.</param>
        /// <returns>A <see cref="IDisposable"/> instance which can be disposed to unsubscribe the observer from the lifecycle.</returns>
        public static IDisposable Subscribe(this ILifecycleObservable observable, string observerName, int stage, Func <CancellationToken, Task> onStart, Func <CancellationToken, Task> onStop)
        {
            if (observable is null)
            {
                throw new ArgumentNullException(nameof(observable));
            }

            if (onStart is null)
            {
                throw new ArgumentNullException(nameof(onStart));
            }

            if (onStop is null)
            {
                return(StartupObserver.Create(observable, observerName, stage, onStart));
            }

            return(observable.Subscribe(observerName, stage, new Observer(onStart, onStop)));
        }
Beispiel #2
0
            public static IDisposable Create(ILifecycleObservable observable, string observerName, int stage, Func <CancellationToken, Task> onStart)
            {
                var observer = new StartupObserver(observable, observerName, stage, onStart);

                return(observer._registration);
            }