Skip to content

Latest commit

 

History

History
85 lines (58 loc) · 1.84 KB

README.md

File metadata and controls

85 lines (58 loc) · 1.84 KB

Neuroglia StartupTasks

.NET Standard library that provides abstractions and implementations to manage startup tasks

Usage

Neuroglia.StartupTasks

Nuget Package

  dotnet add package Neuroglia.StartupTasks

Neuroglia.StartupTasks.AspNetCore

Nuget Package

  dotnet add package Neuroglia.StartupTasks.AspNetCore

Sample Code

Create a new StartupTask

 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");
      }

  }

Register the StartupTask with the DependencyInjection

public void ConfigureServices(IServiceCollection services)
{

    ...

    services.AddStartupTask<MyStartupTask>();

    //Optionally add the StartupTask health check:
    services.AddHealthChecks()
      .AddCheck<StartupTasksHealthCheck>("Startup Tasks");

    ...
}

Optionally register the StartupTaskMiddleware, used for health checks

 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 {
    if (env.IsDevelopment())
        app.UseDeveloperExceptionPage();

    app.UseHealthChecks("/healthz");

    app.UseStartupTasks();

    ...
 }

Contributing

Please see CONTRIBUTING.md for instructions on how to contribute.