// IHostedService adapter that hands every registered ISelfTestStep to // Dalamud's ISelfTestRegistry once the host is up. Resolving the steps // through DI keeps the plugin entry point free of static Plugin.X // lookups - the DI container collects each step that was registered as // IEnumerable. using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Dalamud.Plugin.SelfTest; using Dalamud.Plugin.Services; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace Anvil.Hosting; internal sealed class SelfTestRegistrationHostedService : IHostedService { private readonly ISelfTestRegistry _registry; private readonly IEnumerable _steps; private readonly ILogger _logger; public SelfTestRegistrationHostedService( ISelfTestRegistry registry, IEnumerable steps, ILogger logger ) { _registry = registry; _steps = steps; _logger = logger; } public Task StartAsync(CancellationToken cancellationToken) { var stepList = new List(_steps); _registry.RegisterTestSteps(stepList); _logger.LogInformation("Anvil registered {Count} self-test step(s)", stepList.Count); return Task.CompletedTask; } public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; }