diff --git a/Toolkit.Foundation/Component.cs b/Toolkit.Foundation/Component.cs index 37639e1..efa64ef 100644 --- a/Toolkit.Foundation/Component.cs +++ b/Toolkit.Foundation/Component.cs @@ -12,7 +12,7 @@ public class Component : this.builder = builder; } - public static TComponent? Create(IServiceProvider provider, + public static TComponent? Register(IServiceProvider provider, Action builderDelegate) where TComponent : class, IComponent { diff --git a/Toolkit.Foundation/ComponentBuilder.cs b/Toolkit.Foundation/ComponentBuilder.cs index ca508c4..cf12543 100644 --- a/Toolkit.Foundation/ComponentBuilder.cs +++ b/Toolkit.Foundation/ComponentBuilder.cs @@ -9,16 +9,27 @@ public class ComponentBuilder : { private readonly IHostBuilder hostBuilder; - private bool configurationRegistered; + private ContentRootConfiguration rootConfiguration = new(); + + public void SetRootConfiguration(Action configurationDelegate) + { + ContentRootConfiguration rootConfiguration = new(); + configurationDelegate.Invoke(rootConfiguration); + + this.rootConfiguration = rootConfiguration; + } + + public void SetAppConfiguration(Action 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(); @@ -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(); } diff --git a/Toolkit.Foundation/ComponentFactory.cs b/Toolkit.Foundation/ComponentFactory.cs index a7988be..37e59c5 100644 --- a/Toolkit.Foundation/ComponentFactory.cs +++ b/Toolkit.Foundation/ComponentFactory.cs @@ -8,7 +8,7 @@ public class ComponentFactory(IServiceProvider provider, IComponentFactory { public IComponentHost? Create(string name, - TConfiguration configuration, + TConfiguration? configuration = null, Action? servicesDelegate = null) where TComponent : IComponent where TConfiguration : ComponentConfiguration, new() @@ -16,6 +16,7 @@ public class ComponentFactory(IServiceProvider provider, if (provider.GetRequiredService() is TComponent component) { IComponentBuilder builder = component.Create(); + builder.AddServices(services => { services.AddTransient(_ => diff --git a/Toolkit.Foundation/ContentRootConfiguration.cs b/Toolkit.Foundation/ContentRootConfiguration.cs new file mode 100644 index 0000000..54c3242 --- /dev/null +++ b/Toolkit.Foundation/ContentRootConfiguration.cs @@ -0,0 +1,8 @@ +namespace Toolkit.Foundation; + +public record ContentRootConfiguration +{ + public string ContentRoot { get; set; } = "Local"; + + public string JsonFileName { get; set; } = "Settings.json"; +} \ No newline at end of file diff --git a/Toolkit.Foundation/IComponentFactory.cs b/Toolkit.Foundation/IComponentFactory.cs index 451f30f..82e4f72 100644 --- a/Toolkit.Foundation/IComponentFactory.cs +++ b/Toolkit.Foundation/IComponentFactory.cs @@ -5,7 +5,8 @@ namespace Toolkit.Foundation; public interface IComponentFactory { IComponentHost? Create(string name, - TConfiguration configuration, Action? servicesDelegate = null) + TConfiguration? configuration = null, + Action? servicesDelegate = null) where TComponent : IComponent where TConfiguration : ComponentConfiguration, new(); } \ No newline at end of file diff --git a/Toolkit.UI.Controls.Avalonia/NavigationView/NavigationViewItem.cs b/Toolkit.UI.Controls.Avalonia/NavigationView/NavigationViewItem.cs index f65fade..c6fd2da 100644 --- a/Toolkit.UI.Controls.Avalonia/NavigationView/NavigationViewItem.cs +++ b/Toolkit.UI.Controls.Avalonia/NavigationView/NavigationViewItem.cs @@ -5,4 +5,12 @@ public class NavigationViewItem : { protected override Type StyleKeyOverride => typeof(FluentAvalonia.UI.Controls.NavigationViewItem); -} \ No newline at end of file +} + + +public class NavigationViewItemSeparator : + FluentAvalonia.UI.Controls.NavigationViewItemSeparator +{ + protected override Type StyleKeyOverride => + typeof(FluentAvalonia.UI.Controls.NavigationViewItemSeparator); +}