Files
Walleby/Bitvault/ItemActivatedHandler.cs
T
2024-05-12 20:21:55 +01:00

23 lines
1.0 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Toolkit.Foundation;
namespace Bitvault;
public class ItemActivatedHandler(IServiceProvider serviceProvider,
IProxyService<IPublisher> proxyPublisher) :
INotificationHandler<ActivatedEventArgs<Item>>
{
public async Task Handle(ActivatedEventArgs<Item> args,
CancellationToken cancellationToken = default)
{
IServiceScope serviceScope = serviceProvider.CreateScope();
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
if (serviceFactory.Create<ItemNavigationViewModel>(2, "efesf", "Description " + 1) is ItemNavigationViewModel viewModel)
{
// somehow, we need to get back out of the scope back to the compoment level, this currently doesnt work, and we need a better and cleaner way
await proxyPublisher.Proxy.Publish(new CreateEventArgs<ItemNavigationViewModel>(viewModel),
nameof(ContainerViewModel), cancellationToken);
}
}
}