< Summary

Information
Class: TeleFlow.Framework.Application.TeleFlowApplicationLifecycleRunner
Assembly: TeleFlow.Framework.Core
File(s): /_/src/TeleFlow.Framework.Core/Application/TeleFlowApplicationLifecycleRunner.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 67
Line coverage: 100%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%66100%
RunStartupAsync()100%22100%
RunShutdownAsync()100%22100%
ExecuteStartupTaskAsync()100%11100%
ExecuteShutdownTaskAsync()100%11100%

File(s)

/_/src/TeleFlow.Framework.Core/Application/TeleFlowApplicationLifecycleRunner.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2
 3namespace TeleFlow.Framework.Application;
 4
 5/// <summary>
 6/// Executes TeleFlow application lifecycle tasks around update source execution.
 7/// This runner is transport-agnostic so plain application execution and future hosting integration
 8/// can share the same startup and shutdown semantics.
 9/// </summary>
 10internal sealed class TeleFlowApplicationLifecycleRunner
 11{
 12    private readonly IServiceScopeFactory _scopeFactory;
 13    private readonly IReadOnlyList<TeleFlowStartupTaskRegistration> _startupTasks;
 14    private readonly IReadOnlyList<TeleFlowShutdownTaskRegistration> _shutdownTasks;
 15
 16    public TeleFlowApplicationLifecycleRunner(
 17        IServiceScopeFactory scopeFactory,
 18        IReadOnlyList<TeleFlowStartupTaskRegistration> startupTasks,
 19        IReadOnlyList<TeleFlowShutdownTaskRegistration> shutdownTasks)
 20    {
 4821        _scopeFactory = scopeFactory ?? throw new ArgumentNullException(nameof(scopeFactory));
 4822        _startupTasks = startupTasks ?? throw new ArgumentNullException(nameof(startupTasks));
 4823        _shutdownTasks = shutdownTasks ?? throw new ArgumentNullException(nameof(shutdownTasks));
 4824    }
 25
 26    public async ValueTask RunStartupAsync(CancellationToken cancellationToken = default)
 27    {
 10028        foreach (var registration in _startupTasks)
 29        {
 730            await ExecuteStartupTaskAsync(registration.TaskType, cancellationToken).ConfigureAwait(false);
 31        }
 4232    }
 33
 34    public async ValueTask RunShutdownAsync(CancellationToken cancellationToken = default)
 35    {
 9636        for (var index = _shutdownTasks.Count - 1; index >= 0; index--)
 37        {
 738            await ExecuteShutdownTaskAsync(_shutdownTasks[index].TaskType, cancellationToken).ConfigureAwait(false);
 39        }
 4140    }
 41
 42    private async ValueTask ExecuteStartupTaskAsync(
 43        Type taskType,
 44        CancellationToken cancellationToken)
 45    {
 746        var scope = _scopeFactory.CreateAsyncScope();
 747        await using (scope.ConfigureAwait(false))
 48        {
 749            var task = (ITeleFlowStartupTask)ActivatorUtilities.CreateInstance(scope.ServiceProvider, taskType);
 50
 751            await task.ExecuteAsync(cancellationToken).ConfigureAwait(false);
 52        }
 553    }
 54
 55    private async ValueTask ExecuteShutdownTaskAsync(
 56        Type taskType,
 57        CancellationToken cancellationToken)
 58    {
 759        var scope = _scopeFactory.CreateAsyncScope();
 760        await using (scope.ConfigureAwait(false))
 61        {
 762            var task = (ITeleFlowShutdownTask)ActivatorUtilities.CreateInstance(scope.ServiceProvider, taskType);
 63
 764            await task.ExecuteAsync(cancellationToken).ConfigureAwait(false);
 65        }
 666    }
 67}