Void.Libs.Bootstrap Help

Quickstart

1. Install NuGet package

dotnet add NullOpsDevs.Bootstrap
<ItemGroup> <PackageReference Include="NullOpsDevs.Bootstrap" Version="<...>" /> </ItemGroup>

2. Create your first bootstrap action

internal class ExampleBootstrapAction : IBootstrapPipelineAction { // Name of the action. // Will be returned by the middleware to the frontend. public string Name => "Example action"; // Actual task logic. public async Task<bool> Invoke(CancellationToken cancellationToken) { // Artificial delay. await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); // Return true if your action succeeded or false otherwise. return true; } }

3. Register your pipeline

builder.Services.AddBootstrapPipeline(x => { x.Use<ExampleBootstrapAction>(); });

4. Register required services and a middleware

builder.Services.UseBootstrap(); // ... and after WebApplicationBuilder.Build() app.UseBootstrapMiddleware();

This method also accepts ErrorBootstrapBehavior as an argument. It specifies how service should handle erroneous state.

4.1. Select which ErrorBootstrapBehavior do you want

Value

Behavior

ExitOnError

The service will shutdown on bootstrap error. Can be used for automatic restart (when running under docker, systemd, etc.)

Continue

Service will continue working, middleware will always return an error.

5. Full source code

Here's what our Program.cs looks like:

using Void.Libs.Bootstrap; using Void.Libs.Bootstrap.Base; using Void.Libs.Bootstrap.Enums; using Void.Libs.Bootstrap.Services; var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); builder.Services.AddBootstrapPipeline(x => { x.Use<ExampleBootstrapAction>(); }); builder.Services.UseBootstrap(ErrorBootstrapBehavior.Continue); var app = builder.Build(); app.Services.GetRequiredService<IBootstrapService>(); app.UseBootstrapMiddleware(); app.MapControllers(); app.Run(); internal class ExampleBootstrapAction : IBootstrapPipelineAction { public string Name => "Example action"; public async Task<bool> Invoke(CancellationToken cancellationToken) { await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); return true; } }

For a complete example, please see the example source code.

02 November 2025