Files
Hyperbar/Hyperbar.Widget/WidgetStartedHandler.cs
TheXamlGuy 565c6866d8 wip
2024-02-10 20:19:01 +00:00

21 lines
658 B
C#

using Microsoft.Extensions.DependencyInjection;
namespace Hyperbar.Widget;
public class WidgetStartedHandler(IPublisher publisher) :
INotificationHandler<Started<IWidgetHost>>
{
public async Task Handle(Started<IWidgetHost> notification,
CancellationToken cancellationToken)
{
if (notification.Value is IWidgetHost host)
{
if (host.Services.GetService<IWidgetViewModel>() is IWidgetViewModel viewModel)
{
await publisher.PublishAsync(new Create<IWidgetViewModel>(viewModel),
nameof(IWidgetHostViewModel), cancellationToken);
}
}
}
}