.NET Standard library that provides abstractions and implementations to manage startup tasks
dotnet add package Neuroglia.StartupTasks
dotnet add package Neuroglia.StartupTasks.AspNetCore
public class MyStartupTask
: StartupTask
{
public MyStartupTask(ILogger<MyStartupTask> logger, IStartupTaskManager startupTaskManager)
: base(startupTaskManager)
{
this.Logger = logger;
}
protected ILogger Logger { get; }
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
this.Logger.LogInformation("Starting the application...");
await Task.Delay(5000);
this.Logger.LogInformation("Application started");
}
}
public void ConfigureServices(IServiceCollection services)
{
...
services.AddStartupTask<MyStartupTask>();
//Optionally add the StartupTask health check:
services.AddHealthChecks()
.AddCheck<StartupTasksHealthCheck>("Startup Tasks");
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
app.UseDeveloperExceptionPage();
app.UseHealthChecks("/healthz");
app.UseStartupTasks();
...
}
Please see CONTRIBUTING.md for instructions on how to contribute.