Improvement to navigation regions
This commit is contained in:
@@ -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>();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record ComponentScope(string Name);
|
||||
@@ -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>())
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface INavigationRegion
|
||||
{
|
||||
void Register(string name,
|
||||
object target);
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface INavigationContextCollection :
|
||||
public interface INavigationRegionCollection :
|
||||
IDictionary<object, object?>;
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface INavigationContextProvider
|
||||
public interface INavigationRegionProvider
|
||||
{
|
||||
object? Get(object key);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record NamedComponent(string Name)
|
||||
{
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
@@ -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;
|
||||
+2
-2
@@ -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;
|
||||
@@ -6,7 +6,7 @@ public class NavigationScope(IPublisher publisher,
|
||||
IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
INavigationProvider navigationProvider,
|
||||
INavigationContextProvider navigationContextProvider,
|
||||
INavigationRegionProvider navigationContextProvider,
|
||||
IContentTemplateDescriptorProvider contentTemplateDescriptorProvider) :
|
||||
INavigationScope
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user