Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/NeverMorewd/Hosting.Avaloniaui
.NET Generic Host support for Avaloniaui app
https://github.com/NeverMorewd/Hosting.Avaloniaui
Last synced: 19 days ago
JSON representation
.NET Generic Host support for Avaloniaui app
- Host: GitHub
- URL: https://github.com/NeverMorewd/Hosting.Avaloniaui
- Owner: NeverMorewd
- License: mit
- Created: 2024-07-29T09:51:43.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-09-27T09:51:48.000Z (about 1 month ago)
- Last Synced: 2024-10-01T07:25:02.287Z (about 1 month ago)
- Language: C#
- Size: 132 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-avalonia - Lemon.Hosting.Avaloniaui - A lightweight module navigation framework built on top of the Microsoft Dependency Injection (MSDI) for AvaloniaUI. (Libraries & Extensions / Generic)
README
# 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)