Rename projects to better structure it. The aim is to try and keep it not dependant on the type of UI framework it uses thus allowing us to switch to another UI framework if we need later...
This commit is contained in:
@@ -23,15 +23,16 @@ public class ConfigurationWriter<TConfiguration>(string path,
|
||||
|
||||
private readonly JsonSerializerOptions? serializerOptions = serializerOptions ??= DefaultSerializerOptions();
|
||||
|
||||
public void Write(Action<TConfiguration?>? updateDelegate = null)
|
||||
public void Write(Action<TConfiguration> updateDelegate)
|
||||
{
|
||||
TConfiguration? updatedValue = TryGet(out TConfiguration? value) ? value : new TConfiguration();
|
||||
|
||||
updateDelegate?.Invoke(updatedValue);
|
||||
Write(updatedValue);
|
||||
if ((TryGet(out TConfiguration? value) ? value : new TConfiguration()) is TConfiguration updatedValue)
|
||||
{
|
||||
updateDelegate?.Invoke(updatedValue);
|
||||
Write(updatedValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(TConfiguration? value)
|
||||
public void Write(TConfiguration value)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
@@ -81,7 +82,7 @@ public class ConfigurationWriter<TConfiguration>(string path,
|
||||
stream.SetLength(stream.Position);
|
||||
}
|
||||
|
||||
private bool TryGet<T>(out T? value)
|
||||
private bool TryGet(out TConfiguration? value)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
@@ -90,7 +91,7 @@ public class ConfigurationWriter<TConfiguration>(string path,
|
||||
using JsonDocument jsonDocument = JsonDocument.Parse(jsonContent);
|
||||
if (jsonDocument.RootElement.TryGetProperty(section, out JsonElement sectionValue))
|
||||
{
|
||||
value = JsonSerializer.Deserialize<T>(sectionValue.ToString(), serializerOptions);
|
||||
value = JsonSerializer.Deserialize<TConfiguration>(sectionValue.ToString(), serializerOptions);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace Hyperbar.Options
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
{
|
||||
void Write(Action<TConfiguration?>? updateDelegate = null);
|
||||
void Write(Action<TConfiguration> updateDelegate);
|
||||
|
||||
void Write(TConfiguration? value);
|
||||
void Write(TConfiguration value);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,6 @@ public interface IWritableConfiguration<out TConfiguration> :
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
{
|
||||
void Update(Action<TConfiguration?> updateAction,
|
||||
void Write(Action<TConfiguration> updateAction,
|
||||
bool reload = true);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class WritableConfiguration<TConfiguration>(IConfigurationWriter<TConfigu
|
||||
|
||||
public TConfiguration Get(string? name) => options.Get(name);
|
||||
|
||||
public void Update(Action<TConfiguration?> updateDelegate,
|
||||
public void Write(Action<TConfiguration> updateDelegate,
|
||||
bool reload = true)
|
||||
{
|
||||
writer.Write(updateDelegate);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Hyperbar.Lifecycles;
|
||||
using Hyperbar.Options;
|
||||
using Hyperbar.Templates;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -11,16 +10,15 @@ using System.Text.Json;
|
||||
namespace Hyperbar;
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection ConfigureWritableOptions<TConfiguration>(this IServiceCollection services,
|
||||
string path = "Settings.json",
|
||||
Func<JsonSerializerOptions>? defaultSerializerOptions = null)
|
||||
public static IServiceCollection AddWritableConfiguration<TConfiguration>(this IServiceCollection services,
|
||||
string path = "Settings.json")
|
||||
where TConfiguration :
|
||||
class, new()
|
||||
{
|
||||
return services.ConfigureWritableOptions<TConfiguration>(typeof(TConfiguration).Name, path);
|
||||
return services.AddWritableConfiguration<TConfiguration>(typeof(TConfiguration).Name, path);
|
||||
}
|
||||
|
||||
public static IServiceCollection ConfigureWritableOptions<TConfiguration>(this IServiceCollection services,
|
||||
public static IServiceCollection AddWritableConfiguration<TConfiguration>(this IServiceCollection services,
|
||||
string section,
|
||||
string path = "Settings.json",
|
||||
Action<JsonSerializerOptions>? serializerDelegate = null)
|
||||
@@ -59,16 +57,16 @@ public static class IServiceCollectionExtensions
|
||||
|
||||
public static IServiceCollection AddCommandTemplate<TCommand, TCommandTemplate>(this IServiceCollection services)
|
||||
where TCommand :
|
||||
ICommandViewModel
|
||||
ICommandWidgetViewModel
|
||||
{
|
||||
Type dataType = typeof(TCommand);
|
||||
Type templateType = typeof(TCommandTemplate);
|
||||
|
||||
string key = dataType.Name;
|
||||
|
||||
services.AddTransient(typeof(ICommandViewModel), dataType);
|
||||
services.AddTransient(typeof(ICommandWidgetViewModel), dataType);
|
||||
services.AddTransient(templateType);
|
||||
services.AddKeyedTransient(typeof(ICommandViewModel), key, dataType);
|
||||
services.AddKeyedTransient(typeof(ICommandWidgetViewModel), key, dataType);
|
||||
services.AddKeyedTransient(templateType, key);
|
||||
|
||||
services.AddTransient<IDataTemplateDescriptor>(provider => new DataTemplateDescriptor
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Hyperbar.Lifecycles;
|
||||
|
||||
public class CommandContext(IServiceProvider serviceProvider) :
|
||||
ICommandContext
|
||||
public class CommandWidgetContext(IServiceProvider serviceProvider) :
|
||||
ICommandWidgetContext
|
||||
{
|
||||
public IServiceProvider ServiceProvider => serviceProvider;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Hyperbar.Lifecycles;
|
||||
|
||||
public interface ICommandBuilder
|
||||
public interface ICommandWidgetBuilder
|
||||
{
|
||||
void Create(IServiceCollection services);
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar.Lifecycles;
|
||||
|
||||
public interface ICommandContext
|
||||
public interface ICommandWidgetContext
|
||||
{
|
||||
IServiceProvider ServiceProvider { get; }
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar.Lifecycles;
|
||||
|
||||
public interface ICommandViewModel
|
||||
public interface ICommandWidgetViewModel
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user