Configuration

This commit is contained in:
Jöran Malek 2024-02-11 02:39:36 +01:00
parent f703567aed
commit 6a9c9e006c
8 changed files with 72 additions and 20 deletions

View file

@ -5,18 +5,48 @@ using Avalonia.Markup.Xaml;
using InkForge.Common.ViewModels;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using ReactiveUI;
using Splat;
using Splat.Microsoft.Extensions.DependencyInjection;
namespace InkForge.Common;
public partial class App : Application
{
public static readonly StyledProperty<IServiceProvider> ServiceProviderProperty = AvaloniaProperty.Register<App, IServiceProvider>(nameof(ServiceProvider));
public static readonly StyledProperty<IServiceProvider> ServiceProviderProperty
= AvaloniaProperty.Register<App, IServiceProvider>(
name: nameof(ServiceProvider),
coerce: OnServiceProviderChanged);
public IServiceProvider ServiceProvider => GetValue(ServiceProviderProperty);
public static void Configure(IServiceCollection services, IConfigurationManager configuration)
{
configuration.SetBasePath(AppContext.BaseDirectory);
configuration.AddJsonFile(
new ManifestEmbeddedFileProvider(typeof(App).Assembly),
"Properties/Settings.json", false, false);
configuration.AddJsonFile(
Path.Combine(
Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData,
Environment.SpecialFolderOption.DoNotVerify),
"InkForge",
"UserSettings.json"), true, true);
configuration.AddJsonFile("Settings.json", true, true);
services.UseMicrosoftDependencyResolver();
Locator.CurrentMutable.InitializeSplat();
Locator.CurrentMutable.InitializeReactiveUI();
services.AddInkForge();
}
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
@ -36,4 +66,10 @@ public partial class App : Application
base.OnFrameworkInitializationCompleted();
}
private static IServiceProvider OnServiceProviderChanged(AvaloniaObject @object, IServiceProvider provider)
{
provider.UseMicrosoftDependencyResolver();
return provider;
}
}

View file

@ -5,6 +5,7 @@
<RootNamespace>InkForge</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
<ItemGroup>
@ -12,8 +13,10 @@
<PackageReference Include="Avalonia.Fonts.Inter" />
<PackageReference Include="Avalonia.ReactiveUI" />
<PackageReference Include="Avalonia.Themes.Fluent" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" />
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="Splat.Microsoft.Extensions.DependencyInjection" />
</ItemGroup>
<ItemGroup>
@ -21,4 +24,8 @@
<ProjectReference Include="..\..\shared\migrations\InkForge.Sqlite\InkForge.Sqlite.csproj" />
</ItemGroup>
</Project>
<ItemGroup>
<EmbeddedResource Include="Properties\Settings.json" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,6 @@
namespace InkForge.Common.Properties;
public class ApplicationSettings
{
public List<string> History { get; } = [];
}

View file

@ -2,6 +2,7 @@ using System.Text.Json.Serialization;
namespace InkForge.Common.Properties;
[JsonSerializable(typeof(ApplicationSettings))]
[JsonSerializable(typeof(IDictionary<string, object>))]
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
public partial class ConfigContext : JsonSerializerContext;

View file

@ -0,0 +1 @@
{}