LasseVK.Bootstrapping 0.1.2-prerelease

This is a prerelease version of LasseVK.Bootstrapping.
dotnet add package LasseVK.Bootstrapping --version 0.1.2-prerelease
                    
NuGet\Install-Package LasseVK.Bootstrapping -Version 0.1.2-prerelease
                    
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="LasseVK.Bootstrapping" Version="0.1.2-prerelease" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LasseVK.Bootstrapping" Version="0.1.2-prerelease" />
                    
Directory.Packages.props
<PackageReference Include="LasseVK.Bootstrapping" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LasseVK.Bootstrapping --version 0.1.2-prerelease
                    
#r "nuget: LasseVK.Bootstrapping, 0.1.2-prerelease"
                    
#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.
#:package LasseVK.Bootstrapping@0.1.2-prerelease
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LasseVK.Bootstrapping&version=0.1.2-prerelease&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=LasseVK.Bootstrapping&version=0.1.2-prerelease&prerelease
                    
Install as a Cake Tool

LasseVK.Bootstrapping

build codeql

This package implements a way to handle registration of services and configuration in a .NET application using the Microsoft.Extensions.Hosting package.

It allows you to place a ModuleBootstrapper class in each class library, and invoke those during program setup to allow them to register services, without having to expose internal implementations from the libraries.

This means you can move services and configuration registration out of Program.cs and into the libraries where the functionality and services reside.

Discord

You can reach me through my Discord server.

Nuget package

You can find the Nuget package here.

Installation

You can install the package from the command line, using dotnet:

dotnet add package LasseVK.Bootstrapping

Or you can use your favorite IDE which should have a Nuget package manager built in.

Framework support

The package supports the following .NET versions:

  • .NET 8.0 (until november 10, 2026)
  • .NET 9.0 (until november 10, 2026)
  • .NET 10.0 (until november 14, 2028)

This follows the official supported versions policies from Microsoft:

Note: After support for a .NET version ends, the package will still exist on nuget for use with that version, but I won't guarantee that updates to that version will be made.

Usage

After installing the package in your projects, you can create a ModuleBootstrapper class in each class library, and invoke those during program setup to allow them to register services, without having to expose internal implementations from the libraries.

This means you can move services and configuration registration out of Program.cs and into the libraries where the functionality and services reside.

Here's an example, in a separate class library you can declare the following two types:

public interface ISomeService
{
    string GetSomeValue();
}

internal class SomeService : ISomeService
{
    public string GetSomeValue()
    {
        return "Some value";
    }
}

then you also declare a ModuleBootstrapper class in the same project:

public class ModuleBootstrapper : IModuleBootstrapper
{
    public static void Bootstrap(IHostApplicationBuilder builder)
    {
        builder.Services.AddSingleton<ISomeService, SomeService>();
    }
}

I also tend to add an ApplicationBootstrapper class in my main program project that registers everything that is specific to the program:

public class ApplicationBootstrapper : IModuleBootstrapper
{
    public static void Bootstrap(IHostApplicationBuilder builder)
    {
        builder.Bootstrap(new TheClassLibrary.ModuleBootstrapper());
        
        // specific registrations of services found in the main program project
    }
}

Then, in program.cs, you can have the following code:

using LasseVK.Bootstrapping;
using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);
builder.Bootstrap(new ApplicationBootstrapper()); // this in turn calls the class library

var host = builder.Build();
await host.InitializeAsync();
await host.RunAsync();

For my own projects, this might be the entire Program.cs content, with all service registrations moved to the ApplicationBootstrapper class, or into separate project ModuleBootstrapper classes.

If anything is required to run against the host instance after building the host, but before running the application, I try to move this into classes implementing the IModuleInitializer interface. Again, I try to separate concerns into separate class libraries with vertical slices of functionality.

Since calling builder.Bootstrap(new SomeModuleBootstrapper()) will only invoke the Bootstrap method on that type once per type (ie. once for SomeModuleBootstrapper), any class library projects that also rely on other class libraries being registered will all call the Bootstrap method with the respective module bootstrappers from those dependency class libraries. This ensures all services are registered, even if the main program project itself only require a few of them.

At most, you will construct additional instances of the bootstrapper classes on program execution, but each Bootstrap method will only be invoked once.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
0.1.2-prerelease 53 5/26/2026
0.1.1-prerelease 55 5/23/2026
0.1.0-prerelease 61 5/22/2026