Improve sidebar nav
This commit is contained in:
@@ -12,7 +12,7 @@ public class Component :
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public static TComponent? Create<TComponent>(IServiceProvider provider,
|
||||
public static TComponent? Register<TComponent>(IServiceProvider provider,
|
||||
Action<IComponentBuilder> builderDelegate)
|
||||
where TComponent : class, IComponent
|
||||
{
|
||||
|
||||
@@ -9,16 +9,27 @@ public class ComponentBuilder :
|
||||
{
|
||||
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()
|
||||
{
|
||||
hostBuilder = new HostBuilder()
|
||||
.UseContentRoot("Local", true)
|
||||
.ConfigureAppConfiguration(config =>
|
||||
{
|
||||
config.AddJsonFile("Settings.json", true, true);
|
||||
})
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddScoped<IComponentHost, ComponentHost>();
|
||||
@@ -72,13 +83,6 @@ public class ComponentBuilder :
|
||||
where TConfiguration :
|
||||
ComponentConfiguration, new()
|
||||
{
|
||||
if (configurationRegistered)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
configurationRegistered = true;
|
||||
|
||||
hostBuilder.AddConfiguration(section: section,
|
||||
defaultConfiguration: configuration);
|
||||
|
||||
@@ -100,6 +104,12 @@ public class ComponentBuilder :
|
||||
|
||||
public IComponentHost Build()
|
||||
{
|
||||
hostBuilder.UseContentRoot(rootConfiguration.ContentRoot, true)
|
||||
.ConfigureAppConfiguration(config =>
|
||||
{
|
||||
config.AddJsonFile(rootConfiguration.JsonFileName, true, true);
|
||||
});
|
||||
|
||||
IHost host = hostBuilder.Build();
|
||||
return host.Services.GetRequiredService<IComponentHost>();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public class ComponentFactory(IServiceProvider provider,
|
||||
IComponentFactory
|
||||
{
|
||||
public IComponentHost? Create<TComponent, TConfiguration>(string name,
|
||||
TConfiguration configuration,
|
||||
TConfiguration? configuration = null,
|
||||
Action<IServiceCollection>? servicesDelegate = null)
|
||||
where TComponent : IComponent
|
||||
where TConfiguration : ComponentConfiguration, new()
|
||||
@@ -16,6 +16,7 @@ public class ComponentFactory(IServiceProvider provider,
|
||||
if (provider.GetRequiredService<TComponent>() is TComponent component)
|
||||
{
|
||||
IComponentBuilder builder = component.Create();
|
||||
|
||||
builder.AddServices(services =>
|
||||
{
|
||||
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
|
||||
{
|
||||
IComponentHost? Create<TComponent, TConfiguration>(string name,
|
||||
TConfiguration configuration, Action<IServiceCollection>? servicesDelegate = null)
|
||||
TConfiguration? configuration = null,
|
||||
Action<IServiceCollection>? servicesDelegate = null)
|
||||
where TComponent : IComponent
|
||||
where TConfiguration : ComponentConfiguration, new();
|
||||
}
|
||||
@@ -5,4 +5,12 @@ public class NavigationViewItem :
|
||||
{
|
||||
protected override Type StyleKeyOverride =>
|
||||
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