Lifter.Avalonia 2.0.1

dotnet add package Lifter.Avalonia --version 2.0.1
                    
NuGet\Install-Package Lifter.Avalonia -Version 2.0.1
                    
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="Lifter.Avalonia" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lifter.Avalonia" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Lifter.Avalonia" />
                    
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 Lifter.Avalonia --version 2.0.1
                    
#r "nuget: Lifter.Avalonia, 2.0.1"
                    
#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 Lifter.Avalonia@2.0.1
                    
#: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=Lifter.Avalonia&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Lifter.Avalonia&version=2.0.1
                    
Install as a Cake Tool

Lifter.Avalonia

Avalonia UI 12 integration for Lifter, providing HostedApplication support with dependency injection, configuration, IHostedService lifecycle management, and the cross-platform IDialogService.

Features

Dependency Injection - Full IServiceCollection and IServiceProvider support
Configuration - IConfiguration with JSON, environment variables, and user secrets
IHostedService Support - Background services managed by application lifecycle
IDialogService - Native Avalonia dialog windows with full override points
Cross-Platform - Proper Desktop (Window) and Mobile (SingleView) handling
Splash Screen - Optional splash screen during initialization
Customizable - Configurable window settings and lifecycle hooks

Installation

dotnet add package Lifter.Avalonia

Quick Start

1. Create Your Main View

using Avalonia.Controls;
using Lifter.Avalonia;

public partial class MainView : UserControl, IHostedView
{
    public MainView()
    {
        InitializeComponent();
    }
}

2. Create Your App Class

using Lifter.Avalonia;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

public class App : HostedApplication<MainView>
{
    protected override void ConfigureServices(
        IServiceCollection services, 
        IConfiguration configuration)
    {
        // Configure window settings
        services.ConfigureWindow(config =>
        {
            config.Title = "My Avalonia App";
            config.Width = 1024;
            config.Height = 768;
        });

        // Register your services
        services.AddSingleton<IMyService, MyService>();
        
        // Register background services
        services.AddHostedService<MyBackgroundService>();
    }
}

3. Update App.axaml

<avalonia:HostedApplication 
    xmlns="https://github.com/avaloniaui"
    xmlns:avalonia="using:Lifter.Avalonia"
    x:Class="MyApp.App">
</avalonia:HostedApplication>

Advanced Usage

Custom Initialization

Override OnHostInitializedAsync for custom initialization logic:

protected override async Task OnHostInitializedAsync()
{
    // Perform database migration, load cached data, etc.
    var dbContext = Services.GetRequiredService<AppDbContext>();
    await dbContext.Database.MigrateAsync();
}

Splash Screen

Override CreateSplashScreen to show a custom splash screen:

protected override Control? CreateSplashScreen()
{
    return new SplashScreenView();
}

Background Services

Implement IHostedService for long-running background tasks:

public class DataSyncService : IHostedService
{
    public Task StartAsync(CancellationToken cancellationToken)
    {
        // Start background task
        return Task.CompletedTask;
    }

    public Task StopAsync(CancellationToken cancellationToken)
    {
        // Clean up
        return Task.CompletedTask;
    }
}

// Register in ConfigureServices
services.AddHostedService<DataSyncService>();

Platform Support

  • Desktop (Windows, macOS, Linux) - Creates a Window with your view
  • Mobile (iOS, Android via .NET MAUI) - Direct view assignment
  • .NET 10 — targets net10.0
  • Avalonia 12.0

How It Works

Desktop vs Mobile

Desktop (IClassicDesktopStyleApplicationLifetime):

var mainWindow = new Window
{
    Content = mainView,  // Your view becomes window content
    Title = "App",
    Width = 1200,
    Height = 960
};
desktop.MainWindow = mainWindow;
mainWindow.Show();

Mobile (ISingleViewApplicationLifetime):

singleView.MainView = mainView;  // Direct view assignment

Initialization Sequence

  1. Build Host - Create IHost with DI and configuration
  2. Show Splash - Optional splash screen
  3. Async Init - Run OnHostInitializedAsync on background thread
  4. Setup View - Create Window (Desktop) or set MainView (Mobile) on UI thread
  5. Start Services - Start all IHostedService instances

Architecture

HostedApplication<TMainView>
    ├── HostApplicationBuilder (Microsoft.Extensions.Hosting)
    ├── IServiceProvider (Dependency Injection)
    ├── IConfiguration (Configuration)
    └── HostManager (Lifter.Core - manages IHostedService lifecycle)

License

MIT - See LICENSE file for details

  • Lifter.Core - Core abstractions, HostManager, and IDialogService interfaces
  • Lifter.Maui - .NET MAUI integration for Lifter
  • Lifter.Blazor - Blazor WebAssembly integration for Lifter

IDialogService

AvaloniaDialogService shows native Avalonia Window dialogs parented to the desktop main window.

Registration

// In ConfigureServices (App.cs)
services.AddAvaloniaDialogService();

Usage

public class MainView : UserControl, IHostedView
{
    private readonly IDialogService _dialogs;

    public MainView(IDialogService dialogs)
    {
        _dialogs = dialogs;
    }

    private async Task OnDeleteClicked()
    {
        var result = await _dialogs.ShowConfirmAsync(
            "Delete item",
            "Are you sure?",
            new DialogOptions { ButtonSet = DialogButtonSet.YesNo });

        if (result.Confirmed)
        {
            // delete logic
        }
    }
}

Custom Override

Subclass AvaloniaDialogService and register it to customise any aspect of the dialog window:

public class MyDialogService : AvaloniaDialogService
{
    // Override to change which window owns the dialog
    protected override Window? GetOwnerWindow() { ... }

    // Override to fully restyle the dialog window
    protected override Window BuildDialogWindow(string title, DialogOptions options) { ... }

    // Override to change button layout
    protected override Panel BuildButtonPanel(DialogOptions options,
        TaskCompletionSource<DialogResult> tcs, Window dialog) { ... }
}

// Register the custom implementation
services.AddAvaloniaDialogService<MyDialogService>();
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
2.0.1 102 5/9/2026
2.0.0 110 5/9/2026
1.1.0 178 1/15/2026

v2.0.1: Added NuGet README files for all packages. v2.0.0: Migrated to .NET 10 and Avalonia 12; replaced Avalonia.Diagnostics with ProDiagnostics; added AvaloniaDialogService.