btcpayserver/BTCPayServer/Extensions/WebHostExtensions.cs

27 lines
859 B
C#
Raw Normal View History

2020-06-28 11:00:51 +02:00
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
2020-06-28 11:00:51 +02:00
using BTCPayServer.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Hosting
{
public static class WebHostExtensions
{
public static async Task StartWithTasksAsync(this IWebHost webHost, CancellationToken cancellationToken = default)
{
// Load all tasks from DI
var startupTasks = webHost.Services.GetServices<IStartupTask>();
// Execute all the tasks
foreach (var startupTask in startupTasks)
{
await startupTask.ExecuteAsync(cancellationToken).ConfigureAwait(false);
}
// Start the tasks as normal
await webHost.StartAsync(cancellationToken).ConfigureAwait(false);
}
}
}