using Microsoft.Extensions.DependencyInjection; namespace Hyperbar.Windows.MediaController; public class MediaControllerHandler(IMediator mediator, IServiceScopeProvider scopeProvider) : INotificationHandler> { public async ValueTask Handle(Created notification, CancellationToken cancellationToken) { if (scopeProvider.TryGet(notification.Value, out IServiceScope? serviceScope)) { if (serviceScope is not null) { if (serviceScope.ServiceProvider.GetService>() is IFactory factory) { if (factory.Create() is MediaControllerViewModel mediaControllerViewModel) { await mediator.PublishAsync(new Created(mediaControllerViewModel), cancellationToken); } } } } } }