Skip to content

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

License

Notifications You must be signed in to change notification settings

neuroglia-io/StartupTasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages