Improvement to navigation regions

This commit is contained in:
TheXamlGuy
2024-05-09 22:37:36 +01:00
parent 711353c8e9
commit 54d2b5374d
31 changed files with 173 additions and 184 deletions
+2 -2
View File
@@ -39,8 +39,8 @@ public class ComponentBuilder :
services.AddTransient<INavigationScope, NavigationScope>();
services.AddTransient<INavigationProvider, NavigationProvider>();
services.AddScoped<INavigationContextCollection, NavigationContextCollection>();
services.AddTransient<INavigationContextProvider, NavigationContextProvider>();
services.AddScoped<INavigationRegionCollection, NavigationRegionCollection>();
services.AddTransient<INavigationRegionProvider, NavigationRegionProvider>();
services.AddHandler<NavigateHandler>();
services.AddHandler<NavigateBackHandler>();
+4 -4
View File
@@ -25,10 +25,10 @@ public class ComponentFactory(IServiceProvider provider,
provider.GetRequiredService<IProxyService<IComponentHostCollection>>());
services.AddScoped(_ =>
provider.GetRequiredService<INavigationContextCollection>());
provider.GetRequiredService<INavigationRegionCollection>());
services.AddScoped(_ =>
provider.GetRequiredService<INavigationContextProvider>());
provider.GetRequiredService<INavigationRegionProvider>());
services.AddScoped(_ =>
provider.GetRequiredService<IComponentScopeCollection>());
@@ -37,7 +37,7 @@ public class ComponentFactory(IServiceProvider provider,
provider.GetRequiredService<IComponentScopeProvider>());
services.AddRange(proxy.Services);
services.AddSingleton(new ComponentScope(name));
services.AddSingleton(new NamedComponent(name));
if (servicesDelegate is not null)
{
@@ -45,7 +45,7 @@ public class ComponentFactory(IServiceProvider provider,
}
});
builder.AddConfiguration<TConfiguration>(name, configuration);
builder.AddConfiguration(name, configuration);
IComponentHost host = builder.Build();
scopes.Add(new ComponentScopeDescriptor(name,
+3 -3
View File
@@ -23,10 +23,10 @@ public class ComponentInitializer(IEnumerable<IComponent> components,
provider.GetRequiredService<IProxyService<IComponentHostCollection>>());
services.AddScoped(_ =>
provider.GetRequiredService<INavigationContextCollection>());
provider.GetRequiredService<INavigationRegionCollection>());
services.AddScoped(_ =>
provider.GetRequiredService<INavigationContextProvider>());
provider.GetRequiredService<INavigationRegionProvider>());
services.AddScoped(_ =>
provider.GetRequiredService<IComponentScopeCollection>());
@@ -36,7 +36,7 @@ public class ComponentInitializer(IEnumerable<IComponent> components,
services.AddRange(typedServices.Services);
services.AddSingleton(new ComponentScope(component.GetType().Name));
services.AddSingleton(new NamedComponent(component.GetType().Name));
});
IComponentHost host = builder.Build();
-3
View File
@@ -1,3 +0,0 @@
namespace Toolkit.Foundation;
public record ComponentScope(string Name);
+5 -5
View File
@@ -33,8 +33,8 @@ public class DefaultHostBuilder :
services.AddScoped<IProxyService<IPublisher>>(provider =>
new ProxyService<IPublisher>(provider.GetRequiredService<IPublisher>()));
services.AddScoped<IProxyService<INavigationContextProvider>>(provider =>
new ProxyService<INavigationContextProvider>(provider.GetRequiredService<INavigationContextProvider>()));
services.AddScoped<IProxyService<INavigationRegionProvider>>(provider =>
new ProxyService<INavigationRegionProvider>(provider.GetRequiredService<INavigationRegionProvider>()));
services.AddScoped<IProxyService<IComponentHostCollection>>(provider =>
new ProxyService<IComponentHostCollection>(provider.GetRequiredService<IComponentHostCollection>()));
@@ -45,12 +45,12 @@ public class DefaultHostBuilder :
services.AddTransient<INavigationProvider, NavigationProvider>();
services.AddScoped<INavigationContextCollection, NavigationContextCollection>();
services.AddTransient<INavigationContextProvider, NavigationContextProvider>();
services.AddScoped<INavigationRegionCollection, NavigationRegionCollection>();
services.AddTransient<INavigationRegionProvider, NavigationRegionProvider>();
services.AddTransient<INavigationScope, NavigationScope>();
services.AddSingleton(new ComponentScope("Root"));
services.AddSingleton(new NamedComponent("Root"));
services.AddScoped<IComponentScopeCollection, ComponentScopeCollection>(provider => new ComponentScopeCollection
{
new ComponentScopeDescriptor("Root", provider.GetRequiredService<IServiceProvider>())
+7
View File
@@ -0,0 +1,7 @@
namespace Toolkit.Foundation;
public interface INavigationRegion
{
void Register(string name,
object target);
}
@@ -1,4 +1,4 @@
namespace Toolkit.Foundation;
public interface INavigationContextCollection :
public interface INavigationRegionCollection :
IDictionary<object, object?>;
@@ -1,6 +1,6 @@
namespace Toolkit.Foundation;
public interface INavigationContextProvider
public interface INavigationRegionProvider
{
object? Get(object key);
+6
View File
@@ -0,0 +1,6 @@
namespace Toolkit.Foundation;
public record NamedComponent(string Name)
{
public override string ToString() => Name;
}
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Toolkit.Foundation;
public class NavigateHandler(ComponentScope scope,
public class NavigateHandler(NamedComponent scope,
IComponentScopeProvider provider) :
INotificationHandler<Navigate>
{
@@ -1,12 +0,0 @@
namespace Toolkit.Foundation;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class NavigationContextAttribute : Attribute
{
public NavigationContextAttribute(string name)
{
Name = name;
}
public string Name { get; }
}
@@ -1,4 +0,0 @@
namespace Toolkit.Foundation;
public class NavigationContextCollection : Dictionary<object, object?>,
INavigationContextCollection;
@@ -0,0 +1,4 @@
namespace Toolkit.Foundation;
public class NavigationRegionCollection : Dictionary<object, object?>,
INavigationRegionCollection;
@@ -1,7 +1,7 @@
namespace Toolkit.Foundation;
public class NavigationContextProvider(INavigationContextCollection contexts) :
INavigationContextProvider
public class NavigationRegionProvider(INavigationRegionCollection contexts) :
INavigationRegionProvider
{
public object? Get(object key) =>
contexts.TryGetValue(key, out object? target) ? target : default;
+1 -1
View File
@@ -6,7 +6,7 @@ public class NavigationScope(IPublisher publisher,
IServiceProvider provider,
IServiceFactory factory,
INavigationProvider navigationProvider,
INavigationContextProvider navigationContextProvider,
INavigationRegionProvider navigationContextProvider,
IContentTemplateDescriptorProvider contentTemplateDescriptorProvider) :
INavigationScope
{