feat(configmanager): complete service registrations in App.axaml.cs
Add IDialogService registration using factory pattern for window access. Add GetMainWindow helper method to provide window reference for dialogs.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using JdeScoping.ConfigManager.Services;
|
using JdeScoping.ConfigManager.Services;
|
||||||
@@ -15,17 +16,13 @@ public partial class App : Application
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static IServiceProvider Services { get; private set; } = null!;
|
public static IServiceProvider Services { get; private set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Initializes the Avalonia XAML loader.
|
|
||||||
/// </summary>
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
AvaloniaXamlLoader.Load(this);
|
AvaloniaXamlLoader.Load(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Called when the framework initialization is complete; configures services and sets the main window.
|
|
||||||
/// </summary>
|
|
||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
{
|
{
|
||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
@@ -60,7 +57,16 @@ public partial class App : Application
|
|||||||
services.AddSingleton<IValidationService, ValidationService>();
|
services.AddSingleton<IValidationService, ValidationService>();
|
||||||
services.AddScoped<IConfigFileService, ConfigFileService>();
|
services.AddScoped<IConfigFileService, ConfigFileService>();
|
||||||
|
|
||||||
|
// Platform Services
|
||||||
|
services.AddSingleton<IDialogService>(sp =>
|
||||||
|
new AvaloniaDialogService(GetMainWindow));
|
||||||
|
|
||||||
// ViewModels
|
// ViewModels
|
||||||
services.AddTransient<MainWindowViewModel>();
|
services.AddTransient<MainWindowViewModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Window? GetMainWindow()
|
||||||
|
{
|
||||||
|
return (ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user