Configuration
This commit is contained in:
parent
f703567aed
commit
6a9c9e006c
8 changed files with 72 additions and 20 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||||
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
|
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
|
||||||
|
|
||||||
<AvaloniaVersion>11.0.9</AvaloniaVersion>
|
<AvaloniaVersion>11.0.9</AvaloniaVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -21,7 +20,10 @@
|
||||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
|
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
|
||||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
|
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
|
||||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1" />
|
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.1" />
|
||||||
|
<PackageVersion Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
|
||||||
|
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
|
<PackageVersion Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.1" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||||
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
|
||||||
<PackageVersion Include="ReactiveUI" Version="19.5.41" />
|
<PackageVersion Include="ReactiveUI" Version="19.5.41" />
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,48 @@ using Avalonia.Markup.Xaml;
|
||||||
|
|
||||||
using InkForge.Common.ViewModels;
|
using InkForge.Common.ViewModels;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
|
using Splat;
|
||||||
|
using Splat.Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace InkForge.Common;
|
namespace InkForge.Common;
|
||||||
|
|
||||||
public partial class App : Application
|
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 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()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
|
@ -36,4 +66,10 @@ public partial class App : Application
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IServiceProvider OnServiceProviderChanged(AvaloniaObject @object, IServiceProvider provider)
|
||||||
|
{
|
||||||
|
provider.UseMicrosoftDependencyResolver();
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
<RootNamespace>InkForge</RootNamespace>
|
<RootNamespace>InkForge</RootNamespace>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -12,8 +13,10 @@
|
||||||
<PackageReference Include="Avalonia.Fonts.Inter" />
|
<PackageReference Include="Avalonia.Fonts.Inter" />
|
||||||
<PackageReference Include="Avalonia.ReactiveUI" />
|
<PackageReference Include="Avalonia.ReactiveUI" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" />
|
<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="Microsoft.Extensions.Http" />
|
||||||
|
<PackageReference Include="Splat.Microsoft.Extensions.DependencyInjection" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
@ -21,4 +24,8 @@
|
||||||
<ProjectReference Include="..\..\shared\migrations\InkForge.Sqlite\InkForge.Sqlite.csproj" />
|
<ProjectReference Include="..\..\shared\migrations\InkForge.Sqlite\InkForge.Sqlite.csproj" />
|
||||||
</ItemGroup>
|
</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;
|
namespace InkForge.Common.Properties;
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(ApplicationSettings))]
|
||||||
[JsonSerializable(typeof(IDictionary<string, object>))]
|
[JsonSerializable(typeof(IDictionary<string, object>))]
|
||||||
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
[JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)]
|
||||||
public partial class ConfigContext : JsonSerializerContext;
|
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 @@
|
||||||
|
{}
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia.Desktop" />
|
<PackageReference Include="Avalonia.Desktop" />
|
||||||
<PackageReference Include="Dock.Avalonia" />
|
<PackageReference Include="Dock.Avalonia" />
|
||||||
<PackageReference Include="Splat.Microsoft.Extensions.DependencyInjection" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,31 @@
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
|
||||||
using InkForge.Common;
|
using InkForge.Common;
|
||||||
using InkForge.Common.ViewModels;
|
using InkForge.Common.ViewModels;
|
||||||
using InkForge.Data;
|
|
||||||
using InkForge.Desktop.Views;
|
using InkForge.Desktop.Views;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
|
|
||||||
using Splat;
|
|
||||||
using Splat.Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
|
private static readonly ConfigurationManager Configuration = new();
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
=> BuildAvaloniaApp()
|
=> BuildAvaloniaApp()
|
||||||
.UseMicrosoftDependencyInjection()
|
.UseMicrosoftDependencyInjection()
|
||||||
.StartWithClassicDesktopLifetime(args);
|
.StartWithClassicDesktopLifetime(args, WithMicrosoftDependencyInjection);
|
||||||
|
|
||||||
|
private static void WithMicrosoftDependencyInjection(IClassicDesktopStyleApplicationLifetime lifetime)
|
||||||
|
{
|
||||||
|
Configuration.AddCommandLine(lifetime.Args ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
=> AppBuilder.Configure<App>()
|
=> AppBuilder.Configure<App>()
|
||||||
|
|
@ -31,20 +36,12 @@ static class Program
|
||||||
|
|
||||||
private static void ConfigureServices(IServiceCollection services)
|
private static void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.UseMicrosoftDependencyResolver();
|
|
||||||
var mutableResolver = Locator.CurrentMutable;
|
|
||||||
mutableResolver.InitializeSplat();
|
|
||||||
mutableResolver.InitializeReactiveUI();
|
|
||||||
|
|
||||||
services.AddInkForge();
|
|
||||||
|
|
||||||
services.AddTransient<IViewFor<AppViewModel>, MainWindow>();
|
services.AddTransient<IViewFor<AppViewModel>, MainWindow>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnSetup(this IServiceCollection services, AppBuilder appBuilder)
|
private static void OnSetup(this IServiceCollection services, AppBuilder appBuilder)
|
||||||
{
|
{
|
||||||
var dispatcher = Dispatcher.UIThread;
|
var dispatcher = Dispatcher.UIThread;
|
||||||
|
|
||||||
var app = appBuilder.Instance!;
|
var app = appBuilder.Instance!;
|
||||||
services
|
services
|
||||||
.AddSingleton(app)
|
.AddSingleton(app)
|
||||||
|
|
@ -52,8 +49,9 @@ static class Program
|
||||||
.AddSingleton(app.PlatformSettings!)
|
.AddSingleton(app.PlatformSettings!)
|
||||||
.AddSingleton(dispatcher);
|
.AddSingleton(dispatcher);
|
||||||
|
|
||||||
|
ConfigureServices(services);
|
||||||
|
|
||||||
var serviceProvider = services.BuildServiceProvider();
|
var serviceProvider = services.BuildServiceProvider();
|
||||||
serviceProvider.UseMicrosoftDependencyResolver();
|
|
||||||
app.SetValue(App.ServiceProviderProperty, serviceProvider);
|
app.SetValue(App.ServiceProviderProperty, serviceProvider);
|
||||||
dispatcher.ShutdownFinished += (_, _) => serviceProvider.Dispose();
|
dispatcher.ShutdownFinished += (_, _) => serviceProvider.Dispose();
|
||||||
}
|
}
|
||||||
|
|
@ -61,7 +59,8 @@ static class Program
|
||||||
private static AppBuilder UseMicrosoftDependencyInjection(this AppBuilder builder)
|
private static AppBuilder UseMicrosoftDependencyInjection(this AppBuilder builder)
|
||||||
{
|
{
|
||||||
ServiceCollection services = [];
|
ServiceCollection services = [];
|
||||||
ConfigureServices(services);
|
App.Configure(services, Configuration);
|
||||||
|
|
||||||
builder.AfterSetup(services.OnSetup);
|
builder.AfterSetup(services.OnSetup);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue