LasseVK.Bootstrapping.Maui 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package LasseVK.Bootstrapping.Maui --version 1.0.0
                    
NuGet\Install-Package LasseVK.Bootstrapping.Maui -Version 1.0.0
                    
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.Maui" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LasseVK.Bootstrapping.Maui" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="LasseVK.Bootstrapping.Maui" />
                    
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.Maui --version 1.0.0
                    
#r "nuget: LasseVK.Bootstrapping.Maui, 1.0.0"
                    
#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.Maui@1.0.0
                    
#: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.Maui&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=LasseVK.Bootstrapping.Maui&version=1.0.0
                    
Install as a Cake Tool

LasseVK.Bootstrapping.Maui

build codeql

This package is used in conjunction with the LasseVK.Bootstrapping package to handle initialization of Maui applications.

Maui applications do not follow the regular convention of implementing its application as an IHost implementation. Additionally, the startup code of a Maui application is synchronous in nature, so asynchronous initialization is not possible.

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.Maui

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

See the main nuget package for usage instructions on how to set up bootstrappers and handle service registration.

When defining the initializer types for Maui applications, implement the IMauiAppInitializer interface:

public interface IMauiAppInitializer
{
    void Initialize(MauiApp app);
}

Then in your main application you would typically have a MauiProgram class that, with the use of the bootstrapping system and initialize support, might look like this:

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        MauiAppBuilder builder = MauiApp.CreateBuilder();
        builder.Bootstrap(new ApplicationBootstrapper());
        
        MauiApp app = builder.Build();
        app.Initialize();
        
        return app;
    }
}

The ApplicationBootstrapper class is a class that implements the IApplicationBootstrapper<MauiAppBuilder> or the IModuleBootstrapper interface, and registers services, among other things implementations of IMauiAppInitializer.

Here are examples of these classes:

public class ApplicationBootstrapper : IApplicationBootstrapper<MauiAppBuilder>
{
    public void Bootstrap(MauiAppBuilder builder)
    {
        builder
           .UseMauiApp<App>()
           .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            });

        builder.Services.AddMauiBlazorWebView();
        builder.Services.AddRadzenComponents();
            
#if DEBUG
        builder.Services.AddBlazorWebViewDeveloperTools();
        builder.Logging.AddDebug();
#endif

        builder.Services.AddSingleton<IMauiAppInitializer, DatabaseMigrationInitializer>();
    }
}

internal sealed class DatabaseMigrationInitializer : IMauiAppInitializer
{
    private readonly IDbContextFactory<AppDbContext> _contextFactory;

    public DatabaseMigrationInitializer(IDbContextFactory<AppDbContext> contextFactory)
    {
        _contextFactory = contextFactory;
    }

    public void Initialize(MauiApp app)
    {
        using AppDbContext context = _contextFactory.CreateDbContext();
        context.Database.Migrate();
    }
}

During startup, the program will first call the Bootstrap method of the ApplicationBootstrapper class, which will register the services that are needed for the application to run, including the IMauiAppInitializer implementation.

In this case the initializer will run migrations as part of the application startup, before the main application code is executed.

Asynchronous initialization

The main nuget package allows for asynchronous initialization of modules and applications, but unfortunately the startup code in a Maui application is synchronous, so these are not supported.

Any attempt at invoking the asynchronous initialization methods using code like this:

initializer.InitializeAsync(app).GetAwaiter().GetResult();

will deadlock the main thread, and the application will never start. As such, registering any asynchronous initializers in a Maui application is not supported. Since this cannot be detected at compile time, it will throw an InvalidOperationException at runtime.

Product Compatible and additional computed target framework versions.
.NET 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