Too much to name... but damn, it got where we are needed

This commit is contained in:
TheXamlGuy
2024-01-14 15:06:30 +00:00
parent 66f4bb8757
commit 1283e8ff58
59 changed files with 511 additions and 250 deletions
@@ -0,0 +1,28 @@
using Microsoft.Extensions.DependencyInjection;
namespace Hyperbar.Windows.MediaController;
public class MediaControllerHandler(IMediator mediator,
IServiceScopeProvider<MediaController> scopeProvider) :
INotificationHandler<Created<MediaController>>
{
public async ValueTask Handle(Created<MediaController> notification,
CancellationToken cancellationToken)
{
if (scopeProvider.TryGet(notification.Value, out IServiceScope? serviceScope))
{
if (serviceScope is not null)
{
if (serviceScope.ServiceProvider.GetService<IFactory<MediaControllerViewModel?>>()
is IFactory<MediaControllerViewModel?> factory)
{
if (factory.Create() is MediaControllerViewModel mediaControllerViewModel)
{
await mediator.PublishAsync(new Created<MediaControllerViewModel>(mediaControllerViewModel),
cancellationToken);
}
}
}
}
}
}