Initilize widget setting without starting its host
This commit is contained in:
@@ -3,25 +3,34 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetHostHandler(IMediator mediator) :
|
||||
INotificationHandler<Started<IWidgetHost>>,
|
||||
INotificationHandler<Stopped<IWidgetHost>>
|
||||
INotificationHandler<Created<IWidgetHost>>
|
||||
{
|
||||
public async Task Handle(Started<IWidgetHost> notification,
|
||||
//public async Task Handle(Started<IWidgetHost> notification,
|
||||
// CancellationToken cancellationToken)
|
||||
//{
|
||||
// if (notification.Value is IWidgetHost host)
|
||||
// {
|
||||
// if (host.Services.GetService<IWidgetViewModel>() is IWidgetViewModel viewModel)
|
||||
// {
|
||||
// await mediator.PublishAsync(new Created<IWidgetViewModel>(viewModel),
|
||||
// nameof(WidgetViewModel), cancellationToken);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
public async Task Handle(Created<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is IWidgetHost host)
|
||||
{
|
||||
if (host.Services.GetService<IWidgetViewModel>() is IWidgetViewModel viewModel)
|
||||
if (host.Services.GetServices<IInitialization>() is
|
||||
IEnumerable<IInitialization> initializations)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<IWidgetViewModel>(viewModel),
|
||||
nameof(WidgetViewModel), cancellationToken);
|
||||
foreach (IInitialization initialization in initializations)
|
||||
{
|
||||
await initialization.InitializeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task Handle(Stopped<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user