Can't figure out how to implement StartupTask

This commit is contained in:
Joseph Milazzo 2021-03-17 17:21:59 -05:00
parent e60d84a2c8
commit 4c6758b9b0
2 changed files with 4 additions and 10 deletions

View File

@ -43,10 +43,8 @@ namespace API
logger.LogError(ex, "An error occurred during migration");
}
// Load all tasks from DI (TODO: This is not working - WarmupServicesStartupTask is Null)
// Load all tasks from DI and initialize them (TODO: This is not working - WarmupServicesStartupTask is Null)
var startupTasks = host.Services.GetServices<WarmupServicesStartupTask>();
// Execute all the tasks
foreach (var startupTask in startupTasks)
{
await startupTask.ExecuteAsync();

View File

@ -1,8 +1,8 @@
using System;
using System.IO.Compression;
using System.Linq;
using API.Data;
using API.Extensions;
using API.Interfaces.Services;
using API.Middleware;
using API.Services;
using Hangfire;
@ -18,9 +18,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using IApplicationLifetime = Microsoft.AspNetCore.Hosting.IApplicationLifetime;
namespace API
{
@ -85,10 +83,8 @@ namespace API
// Add the processing server as IHostedService
services.AddHangfireServer();
// services
// .AddStartupTask<WarmupServicesStartupTask>()
// //.TryAddSingleton(services);
//services.AddStartupTask<WarmupServicesStartupTask>(services).
services.AddTransient<IStartupTask, WarmupServicesStartupTask>().TryAddSingleton(services);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.