StartupTasks 1.0.5

dotnet add package StartupTasks --version 1.0.5
NuGet\Install-Package StartupTasks -Version 1.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StartupTasks" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StartupTasks --version 1.0.5
#r "nuget: StartupTasks, 1.0.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StartupTasks as a Cake Addin
#addin nuget:?package=StartupTasks&version=1.0.5

// Install StartupTasks as a Cake Tool
#tool nuget:?package=StartupTasks&version=1.0.5

StartupTasks

Build and test

About The Project

This is a simple library written in C# .NET 6 for adding startup tasks using hosted services.

Getting Started

Add the nuget package reference to your project

  • Using dotnet-cli dotnet add package StartupTasks
  • Using Package Manager Install-Package StartupTasks

Create as class that implements IStartupTask

public class MyStartupTask : IStartupTask
{
    public Task RunAsync(CancellationToken cancellationToken)
    {
        // Startup logic goes here
        return Task.CompletedTask;
    }
}

Register startup tasks with IServiceCollection and add your startup task. Code block below shows common usage scenarios.

using StartupTasks;

var builder = WebApplication.CreateBuilder(args);
    
builder.Services.AddStartupTasks()

    // Adds a startup task that runs first.
    .Add<MyStartupTask>(); 

    // Adds another startup task that runs second.
    .Add<AnotherStartupTask>();

    // Adds a startup task that runs in parlallel
    // and begins before the sequential tasks are
    // executed.
    .Add<ParallelStartupTask>(runInParllel: true)

    // Adds a startup task without a class file.
    // Delegate takes a CancellationToken as parameter
    // and returns a Task.
    .AddAction(async (cancellationToken) => 
        await Console.out.WriteLineAsync("Let's begin", cancellationToken),
        runInParallel: true)

var app = builder.Build();
app.Run();

Roadmap

  • Add startup tasks executed in hosted services
  • Add startup task health check report after all have ran
  • Add option to verification of registered tasks can be resolved at before execution
  • Add startup groups so that groups of startup tasks can run sequentially within it's group but in parallel with other groups

See the open issues for a full list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Albin Ma - ama@almatek.io

Project Link: https://github.com/almatek/dotnet-startup-tasks

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 432 3/8/2022
1.0.4 404 2/20/2022
1.0.3 368 2/20/2022
1.0.2 404 2/19/2022
1.0.1 381 2/16/2022
1.0.0 384 2/15/2022