Repository navigation
1. Introduction π
Scarlet.Extensions.Hosting.DirectN is an unofficial library that integrates DirectN (Win32 / Direct2D) applications with the .NET Generic Host. It is the successor of Extensions.Hosting.Wpf for applications moving off WPF, and keeps its hosting model.
The .NET Generic Host (Microsoft.Extensions.Hosting) provides a standardized way to build applications with:
-
Dependency Injection via
Microsoft.Extensions.DependencyInjection -
Configuration via
Microsoft.Extensions.Configuration(appsettings.json, environment variables, etc.) -
Logging via
Microsoft.Extensions.Logging - Hosted Services for background tasks
Console apps and ASP.NET Core apps benefit from this out of the box. A DirectN application owns a Win32 message loop on a UI thread, which the Generic Host knows nothing about. This library runs that UI thread inside the host, without WPF or WinForms, so the whole application can be published with Native AOT.
| Feature | Description |
|---|---|
| Host integration | Runs the DirectN application inside the Generic Host, on its own UI thread, started after every hosted service and stopped before them |
| Any host builder | Everything is registered on IServiceCollection, so it works with Host.CreateApplicationBuilder and Host.CreateDefaultBuilder alike |
| Components | UI-thread objects (windows, tray icons) created with constructor injection and disposed on the UI thread |
| UI-thread SynchronizationContext | Post and Send to the UI thread from anywhere, at any time, in the caller's ExecutionContext
|
| UI dispatcher |
DirectNDispatcher in the container: Post, and awaitable InvokeAsync that faults instead of hanging when the work can never run |
| Tray icon support | Optional extension with WinForms NotifyIcon behavior and a native Win32 menu |
| Thread switching | Optional extension with JoinableTaskFactory and AsyncLazy<T>, from an AOT-compatible extract of Microsoft.VisualStudio.Threading |
| Native AOT | Every package is IsAotCompatible; the samples and the test suite are published and run as native executables in CI |
Scarlet.Extensions.Hosting.DirectN
Getting Started
Core Features
Extensions
Reference