diff --git a/Directory.Packages.props b/Directory.Packages.props index f5cd323..8ef40b9 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,7 +2,6 @@ true true - 11.0.9 @@ -21,7 +20,10 @@ + + + diff --git a/app/InkForge.Common/App.axaml.cs b/app/InkForge.Common/App.axaml.cs index 136dadf..93890c3 100644 --- a/app/InkForge.Common/App.axaml.cs +++ b/app/InkForge.Common/App.axaml.cs @@ -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 ServiceProviderProperty = AvaloniaProperty.Register(nameof(ServiceProvider)); + public static readonly StyledProperty ServiceProviderProperty + = AvaloniaProperty.Register( + 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; + } } diff --git a/app/InkForge.Common/InkForge.Common.csproj b/app/InkForge.Common/InkForge.Common.csproj index 2d0d625..1225e41 100644 --- a/app/InkForge.Common/InkForge.Common.csproj +++ b/app/InkForge.Common/InkForge.Common.csproj @@ -5,6 +5,7 @@ InkForge enable enable + true @@ -12,8 +13,10 @@ - + + + @@ -21,4 +24,8 @@ - + + + + + \ No newline at end of file diff --git a/app/InkForge.Common/Properties/ApplicationSettings.cs b/app/InkForge.Common/Properties/ApplicationSettings.cs new file mode 100644 index 0000000..3a71946 --- /dev/null +++ b/app/InkForge.Common/Properties/ApplicationSettings.cs @@ -0,0 +1,6 @@ +namespace InkForge.Common.Properties; + +public class ApplicationSettings +{ + public List History { get; } = []; +} diff --git a/app/InkForge.Common/Properties/ConfigContext.cs b/app/InkForge.Common/Properties/ConfigContext.cs index 31c97df..621c320 100644 --- a/app/InkForge.Common/Properties/ConfigContext.cs +++ b/app/InkForge.Common/Properties/ConfigContext.cs @@ -2,6 +2,7 @@ using System.Text.Json.Serialization; namespace InkForge.Common.Properties; +[JsonSerializable(typeof(ApplicationSettings))] [JsonSerializable(typeof(IDictionary))] [JsonSourceGenerationOptions(GenerationMode = JsonSourceGenerationMode.Metadata)] public partial class ConfigContext : JsonSerializerContext; diff --git a/app/InkForge.Common/Properties/Settings.json b/app/InkForge.Common/Properties/Settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/app/InkForge.Common/Properties/Settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/app/InkForge.Desktop/InkForge.Desktop.csproj b/app/InkForge.Desktop/InkForge.Desktop.csproj index 6c8a490..04417cc 100644 --- a/app/InkForge.Desktop/InkForge.Desktop.csproj +++ b/app/InkForge.Desktop/InkForge.Desktop.csproj @@ -11,7 +11,7 @@ - + diff --git a/app/InkForge.Desktop/Program.cs b/app/InkForge.Desktop/Program.cs index aacfa5d..cfb5987 100644 --- a/app/InkForge.Desktop/Program.cs +++ b/app/InkForge.Desktop/Program.cs @@ -1,26 +1,31 @@ using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; using Avalonia.ReactiveUI; using Avalonia.Threading; using InkForge.Common; using InkForge.Common.ViewModels; -using InkForge.Data; using InkForge.Desktop.Views; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using ReactiveUI; -using Splat; -using Splat.Microsoft.Extensions.DependencyInjection; - static class Program { + private static readonly ConfigurationManager Configuration = new(); + [STAThread] public static void Main(string[] args) => BuildAvaloniaApp() .UseMicrosoftDependencyInjection() - .StartWithClassicDesktopLifetime(args); + .StartWithClassicDesktopLifetime(args, WithMicrosoftDependencyInjection); + + private static void WithMicrosoftDependencyInjection(IClassicDesktopStyleApplicationLifetime lifetime) + { + Configuration.AddCommandLine(lifetime.Args ?? []); + } public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() @@ -31,20 +36,12 @@ static class Program private static void ConfigureServices(IServiceCollection services) { - services.UseMicrosoftDependencyResolver(); - var mutableResolver = Locator.CurrentMutable; - mutableResolver.InitializeSplat(); - mutableResolver.InitializeReactiveUI(); - - services.AddInkForge(); - services.AddTransient, MainWindow>(); } private static void OnSetup(this IServiceCollection services, AppBuilder appBuilder) { var dispatcher = Dispatcher.UIThread; - var app = appBuilder.Instance!; services .AddSingleton(app) @@ -52,8 +49,9 @@ static class Program .AddSingleton(app.PlatformSettings!) .AddSingleton(dispatcher); + ConfigureServices(services); + var serviceProvider = services.BuildServiceProvider(); - serviceProvider.UseMicrosoftDependencyResolver(); app.SetValue(App.ServiceProviderProperty, serviceProvider); dispatcher.ShutdownFinished += (_, _) => serviceProvider.Dispose(); } @@ -61,7 +59,8 @@ static class Program private static AppBuilder UseMicrosoftDependencyInjection(this AppBuilder builder) { ServiceCollection services = []; - ConfigureServices(services); + App.Configure(services, Configuration); + builder.AfterSetup(services.OnSetup); return builder; }