An attempt to send messages out of the scope

This commit is contained in:
TheXamlGuy
2024-05-12 20:21:55 +01:00
parent 837e249c64
commit 2842fc7108
11 changed files with 71 additions and 63 deletions
+23
View File
@@ -0,0 +1,23 @@
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);
}
}
}