Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/NeverMorewd/Hosting.Avaloniaui

.NET Generic Host support for Avaloniaui app
https://github.com/NeverMorewd/Hosting.Avaloniaui

Last synced: about 2 months ago
JSON representation

.NET Generic Host support for Avaloniaui app

Awesome Lists containing this project

README

        





NuGet Package Version


AOT Supported
Linux Supported
macOS Supported
Windows Supported

# Introduction
.NET Generic Host support for Avaloniaui desktop app.
Support Aot!
- Examples:
```C#
internal sealed class Program
{
[STAThread]
[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[RequiresDynamicCode("Calls Microsoft.Extensions.Hosting.Host.CreateApplicationBuilder()")]
public static void Main(string[] args)
{
var hostBuilder = Host.CreateApplicationBuilder();

// config IConfiguration
hostBuilder.Configuration
.AddCommandLine(args)
.AddEnvironmentVariables()
.AddInMemoryCollection();

// config ILogger
hostBuilder.Services.AddLogging(builder => builder.AddConsole());
// add some services
hostBuilder.Services.AddSingleton();

#region app default
RunAppDefault(hostBuilder, args);
#endregion

#region app without mainwindow
//RunAppWithoutMainWindow(hostBuilder, args);
#endregion

#region app with serviceprovider
//RunAppWithServiceProvider(hostBuilder, args);
#endregion
}

public static AppBuilder ConfigAvaloniaAppBuilder(AppBuilder appBuilder)
{
return appBuilder
.UsePlatformDetect()
.WithInterFont()
.LogToTrace()
.UseReactiveUI();
}

[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private static void RunAppDefault(HostApplicationBuilder hostBuilder, string[] args)
{
hostBuilder.Services.AddAvaloniauiDesktopApplication(ConfigAvaloniaAppBuilder);
// build host
var appHost = hostBuilder.Build();
// run app
appHost.RunAvaloniauiApplication(args);
}

[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private static void RunAppWithoutMainWindow(HostApplicationBuilder hostBuilder, string[] args)
{
// add avaloniaui application and config AppBuilder
hostBuilder.Services.AddAvaloniauiDesktopApplication(ConfigAvaloniaAppBuilder);
// add MainWindow & MainWindowViewModelWithParams
hostBuilder.Services.AddMainWindow();
// build host
var appHost = hostBuilder.Build();
// run app
appHost.RunAvaloniauiApplication(args);
}

[SupportedOSPlatform("windows")]
[SupportedOSPlatform("linux")]
[SupportedOSPlatform("macos")]
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
private static void RunAppWithServiceProvider(HostApplicationBuilder hostBuilder, string[] args)
{
// add avaloniaui application and config AppBuilder
hostBuilder.Services.AddAvaloniauiDesktopApplication(ConfigAvaloniaAppBuilder);
// add MainWindowViewModelWithParams
hostBuilder.Services.AddSingleton();
// build host
var appHost = hostBuilder.Build();
// run app
appHost.RunAvaloniauiApplication(args);
}
}
```

References:
[Nito.Host.Wpf](https://github.com/StephenCleary/Hosting)