Improve sidebar nav
This commit is contained in:
@@ -12,7 +12,7 @@ public class Component :
|
|||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TComponent? Create<TComponent>(IServiceProvider provider,
|
public static TComponent? Register<TComponent>(IServiceProvider provider,
|
||||||
Action<IComponentBuilder> builderDelegate)
|
Action<IComponentBuilder> builderDelegate)
|
||||||
where TComponent : class, IComponent
|
where TComponent : class, IComponent
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,16 +9,27 @@ public class ComponentBuilder :
|
|||||||
{
|
{
|
||||||
private readonly IHostBuilder hostBuilder;
|
private readonly IHostBuilder hostBuilder;
|
||||||
|
|
||||||
private bool configurationRegistered;
|
private ContentRootConfiguration rootConfiguration = new();
|
||||||
|
|
||||||
|
public void SetRootConfiguration(Action<ContentRootConfiguration> configurationDelegate)
|
||||||
|
{
|
||||||
|
ContentRootConfiguration rootConfiguration = new();
|
||||||
|
configurationDelegate.Invoke(rootConfiguration);
|
||||||
|
|
||||||
|
this.rootConfiguration = rootConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetAppConfiguration(Action<ContentRootConfiguration> rootConfigurationDelegate)
|
||||||
|
{
|
||||||
|
ContentRootConfiguration rootConfiguration = new();
|
||||||
|
rootConfigurationDelegate.Invoke(rootConfiguration);
|
||||||
|
|
||||||
|
this.rootConfiguration = rootConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
private ComponentBuilder()
|
private ComponentBuilder()
|
||||||
{
|
{
|
||||||
hostBuilder = new HostBuilder()
|
hostBuilder = new HostBuilder()
|
||||||
.UseContentRoot("Local", true)
|
|
||||||
.ConfigureAppConfiguration(config =>
|
|
||||||
{
|
|
||||||
config.AddJsonFile("Settings.json", true, true);
|
|
||||||
})
|
|
||||||
.ConfigureServices((context, services) =>
|
.ConfigureServices((context, services) =>
|
||||||
{
|
{
|
||||||
services.AddScoped<IComponentHost, ComponentHost>();
|
services.AddScoped<IComponentHost, ComponentHost>();
|
||||||
@@ -72,13 +83,6 @@ public class ComponentBuilder :
|
|||||||
where TConfiguration :
|
where TConfiguration :
|
||||||
ComponentConfiguration, new()
|
ComponentConfiguration, new()
|
||||||
{
|
{
|
||||||
if (configurationRegistered)
|
|
||||||
{
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
configurationRegistered = true;
|
|
||||||
|
|
||||||
hostBuilder.AddConfiguration(section: section,
|
hostBuilder.AddConfiguration(section: section,
|
||||||
defaultConfiguration: configuration);
|
defaultConfiguration: configuration);
|
||||||
|
|
||||||
@@ -100,6 +104,12 @@ public class ComponentBuilder :
|
|||||||
|
|
||||||
public IComponentHost Build()
|
public IComponentHost Build()
|
||||||
{
|
{
|
||||||
|
hostBuilder.UseContentRoot(rootConfiguration.ContentRoot, true)
|
||||||
|
.ConfigureAppConfiguration(config =>
|
||||||
|
{
|
||||||
|
config.AddJsonFile(rootConfiguration.JsonFileName, true, true);
|
||||||
|
});
|
||||||
|
|
||||||
IHost host = hostBuilder.Build();
|
IHost host = hostBuilder.Build();
|
||||||
return host.Services.GetRequiredService<IComponentHost>();
|
return host.Services.GetRequiredService<IComponentHost>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class ComponentFactory(IServiceProvider provider,
|
|||||||
IComponentFactory
|
IComponentFactory
|
||||||
{
|
{
|
||||||
public IComponentHost? Create<TComponent, TConfiguration>(string name,
|
public IComponentHost? Create<TComponent, TConfiguration>(string name,
|
||||||
TConfiguration configuration,
|
TConfiguration? configuration = null,
|
||||||
Action<IServiceCollection>? servicesDelegate = null)
|
Action<IServiceCollection>? servicesDelegate = null)
|
||||||
where TComponent : IComponent
|
where TComponent : IComponent
|
||||||
where TConfiguration : ComponentConfiguration, new()
|
where TConfiguration : ComponentConfiguration, new()
|
||||||
@@ -16,6 +16,7 @@ public class ComponentFactory(IServiceProvider provider,
|
|||||||
if (provider.GetRequiredService<TComponent>() is TComponent component)
|
if (provider.GetRequiredService<TComponent>() is TComponent component)
|
||||||
{
|
{
|
||||||
IComponentBuilder builder = component.Create();
|
IComponentBuilder builder = component.Create();
|
||||||
|
|
||||||
builder.AddServices(services =>
|
builder.AddServices(services =>
|
||||||
{
|
{
|
||||||
services.AddTransient(_ =>
|
services.AddTransient(_ =>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public record ContentRootConfiguration
|
||||||
|
{
|
||||||
|
public string ContentRoot { get; set; } = "Local";
|
||||||
|
|
||||||
|
public string JsonFileName { get; set; } = "Settings.json";
|
||||||
|
}
|
||||||
@@ -5,7 +5,8 @@ namespace Toolkit.Foundation;
|
|||||||
public interface IComponentFactory
|
public interface IComponentFactory
|
||||||
{
|
{
|
||||||
IComponentHost? Create<TComponent, TConfiguration>(string name,
|
IComponentHost? Create<TComponent, TConfiguration>(string name,
|
||||||
TConfiguration configuration, Action<IServiceCollection>? servicesDelegate = null)
|
TConfiguration? configuration = null,
|
||||||
|
Action<IServiceCollection>? servicesDelegate = null)
|
||||||
where TComponent : IComponent
|
where TComponent : IComponent
|
||||||
where TConfiguration : ComponentConfiguration, new();
|
where TConfiguration : ComponentConfiguration, new();
|
||||||
}
|
}
|
||||||
@@ -6,3 +6,11 @@ public class NavigationViewItem :
|
|||||||
protected override Type StyleKeyOverride =>
|
protected override Type StyleKeyOverride =>
|
||||||
typeof(FluentAvalonia.UI.Controls.NavigationViewItem);
|
typeof(FluentAvalonia.UI.Controls.NavigationViewItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class NavigationViewItemSeparator :
|
||||||
|
FluentAvalonia.UI.Controls.NavigationViewItemSeparator
|
||||||
|
{
|
||||||
|
protected override Type StyleKeyOverride =>
|
||||||
|
typeof(FluentAvalonia.UI.Controls.NavigationViewItemSeparator);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user