using Microsoft.Extensions.DependencyInjection; namespace Toolkit.Foundation; public class NavigateHandler(NamedComponent scope, IComponentScopeProvider componentScopeProvider) : INotificationHandler { public Task Handle(NavigateEventArgs args) { INavigation? navigation = null; if (args.Scope is "self" || args.Scope is "new") { if (args.Sender is IServiceProviderRequired requireServiceProvider) { if (args.Scope is "self") { navigation = requireServiceProvider.Provider.GetRequiredService(); } if (args.Scope is "new") { IServiceScope serviceScope = requireServiceProvider.Provider.CreateScope(); navigation = serviceScope.ServiceProvider.GetRequiredService(); } } } if (navigation is null) { ComponentScopeDescriptor? descriptor = componentScopeProvider.Get(args.Scope ?? scope.Key); navigation = descriptor?.Services?.GetRequiredService(); } navigation?.Navigate(args.Route, args.Sender, args.Region, args.Navigated, args.Parameters); return Task.CompletedTask; } }