namespace NucleicApp.Services; /// Isolates WinUI's DispatcherQueue from the renderer state machine and keeps tests portable. public interface IRendererDispatcher { void Post(Action action); } public sealed class SynchronizationContextDispatcher : IRendererDispatcher { private readonly SynchronizationContext context; public SynchronizationContextDispatcher(SynchronizationContext? context = null) { this.context = context ?? SynchronizationContext.Current ?? throw new InvalidOperationException("renderer has no SynchronizationContext"); } public void Post(Action action) => context.Post(static state => ((Action)state!).Invoke(), action); } public sealed class InlineRendererDispatcher : IRendererDispatcher { public static InlineRendererDispatcher Instance { get; } = new(); private InlineRendererDispatcher() { } public void Post(Action action) => action(); }