Unofficial implementation of Microsoft.Extensions.Hosting for WPF. It is inspired by Dapplo and this extensions is focused only on WPF and doesn't have Plugins, SingleInstance etc features like Dapplo. It's main feature is to provide the ability to bind DataContext with ViewModels directly in XAML where the ViewModel gets resolved by DI. This library also has few extensions packages to add features like tray icon, thread switching between main thread and threadpool thread, 3rd party DI support.
public partial class App : Application, IApplicationInitializeComponent
{
}public class Program
{
public static void Main(string[] args)
{
using IHost host = CreateHostBuilder(args).Build();
host.Run();
}
private static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureServices(ConfigureServices);
}
private static void ConfigureServices(HostBuilderContext hostContext, IServiceCollection services)
{
services.AddWpf<App>();
}
}<StartupObject>[Namespace].Program</StartupObject>For the full guide including ViewModel Locator, constructor injection, and more, see the Wiki.
- HostingSimple: A minimalistic, beginner-friendly introduction. Offers a basic starting point for understanding the framework.
- HostingReactiveUI: An advanced example using NLog for logging, ReactiveUI as the MVVM framework, and the TrayIcon feature.
- HostingReactiveUISimpleInjector: Incorporates SimpleInjector alongside ReactiveUI. Demonstrates that you're not limited to
Microsoft.DependencyInjection. - HostingReactiveUISimpleInjectorAmbientScope: Demonstrates
AsyncScopedLifestylewith SimpleInjector for ambient-scoping and integrates Threading. - HostingReactiveUISimpleInjectorFlowingScope: Demonstrates
ScopedLifestyle.Flowingwith SimpleInjector for closure-scoping. Presents an alternative approach withoutViewModelLocatorHost.
Full documentation is available in the Wiki:
- Getting Started — Minimal setup guide
- ViewModelLocator Feature — Bind DataContext in XAML via DI
- Constructor Injection in App — Inject services into your App class
- Threading — Switch between UI and background threads
- TrayIcon — System tray icon support
- Bootstrap (3rd-party DI) — SimpleInjector, Autofac, and other DI containers
- Architecture & How It Works — Internal architecture and lifecycle
- API Reference — Complete API reference
- FAQ & Troubleshooting — Common questions and error solutions