Configuration
This commit is contained in:
parent
f703567aed
commit
6a9c9e006c
8 changed files with 72 additions and 20 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
6
app/InkForge.Common/Properties/ApplicationSettings.cs
Normal file
6
app/InkForge.Common/Properties/ApplicationSettings.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
namespace InkForge.Common.Properties;
|
||||
|
||||
public class ApplicationSettings
|
||||
{
|
||||
public List<string> History { get; } = [];
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
1
app/InkForge.Common/Properties/Settings.json
Normal file
1
app/InkForge.Common/Properties/Settings.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
Loading…
Add table
Add a link
Reference in a new issue