2020-06-28 11:00:51 +02:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2020-11-17 13:46:23 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|