Improve ComponentBuilder
This commit is contained in:
@@ -9,7 +9,9 @@ public class ComponentBuilder :
|
|||||||
{
|
{
|
||||||
private readonly IHostBuilder hostBuilder;
|
private readonly IHostBuilder hostBuilder;
|
||||||
|
|
||||||
private ComponentContentConfiguration configuration = new();
|
public string ContentRoot { get; set; } = "Local";
|
||||||
|
|
||||||
|
public string ConfigurationFile { get; set; } = "Settings.json";
|
||||||
|
|
||||||
private ComponentBuilder()
|
private ComponentBuilder()
|
||||||
{
|
{
|
||||||
@@ -65,7 +67,7 @@ public class ComponentBuilder :
|
|||||||
where TConfiguration :
|
where TConfiguration :
|
||||||
ComponentConfiguration, new()
|
ComponentConfiguration, new()
|
||||||
{
|
{
|
||||||
hostBuilder.AddConfiguration(section: section,
|
hostBuilder.AddConfiguration(section: section, path: ConfigurationFile,
|
||||||
defaultConfiguration: configuration);
|
defaultConfiguration: configuration);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@@ -86,21 +88,13 @@ public class ComponentBuilder :
|
|||||||
|
|
||||||
public IComponentHost Build()
|
public IComponentHost Build()
|
||||||
{
|
{
|
||||||
hostBuilder.UseContentRoot(configuration.ContentRoot, true)
|
hostBuilder.UseContentRoot(ContentRoot, true)
|
||||||
.ConfigureAppConfiguration(config =>
|
.ConfigureAppConfiguration(config =>
|
||||||
{
|
{
|
||||||
config.AddJsonFile(configuration.JsonFileName, true, true);
|
config.AddJsonFile(ConfigurationFile, true, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
IHost host = hostBuilder.Build();
|
IHost host = hostBuilder.Build();
|
||||||
return host.Services.GetRequiredService<IComponentHost>();
|
return host.Services.GetRequiredService<IComponentHost>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetContentConfiguration(Action<ComponentContentConfiguration> configurationDelegate)
|
|
||||||
{
|
|
||||||
ComponentContentConfiguration configuration = new();
|
|
||||||
configurationDelegate(configuration);
|
|
||||||
|
|
||||||
this.configuration = configuration;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
public record ComponentContentConfiguration
|
public record ComponentContentConfiguration
|
||||||
{
|
{
|
||||||
public string ContentRoot { get; set; } = "Local";
|
// public string ContentRoot { get; set; } = "Local";
|
||||||
|
|
||||||
public string JsonFileName { get; set; } = "Settings.json";
|
public string JsonFileName { get; set; } = "Settings2.json";
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,10 @@ namespace Toolkit.Foundation;
|
|||||||
|
|
||||||
public interface IComponentBuilder
|
public interface IComponentBuilder
|
||||||
{
|
{
|
||||||
|
string ConfigurationFile { get; set; }
|
||||||
|
|
||||||
|
string ContentRoot { get; set; }
|
||||||
|
|
||||||
IComponentBuilder AddConfiguration<TConfiguration>(Action<TConfiguration> configurationDelegate)
|
IComponentBuilder AddConfiguration<TConfiguration>(Action<TConfiguration> configurationDelegate)
|
||||||
where TConfiguration : ComponentConfiguration, new();
|
where TConfiguration : ComponentConfiguration, new();
|
||||||
|
|
||||||
@@ -17,6 +21,4 @@ public interface IComponentBuilder
|
|||||||
IComponentBuilder AddServices(Action<IServiceCollection> configureDelegate);
|
IComponentBuilder AddServices(Action<IServiceCollection> configureDelegate);
|
||||||
|
|
||||||
IComponentHost Build();
|
IComponentHost Build();
|
||||||
|
|
||||||
void SetContentConfiguration(Action<ComponentContentConfiguration> configurationDelegate);
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user