mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Core/UI - Move from Ninject to DryIoc (#754)
This commit is contained in:
1 parent
166cb888c1
commit
b7e723b7e9
121 files changed
+1175
-980
No files matched your search
@@ -7,21 +7,21 @@ using System.Net.Http;
|
||||
using System.Threading;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Windows.Ninject;
|
||||
using Artemis.UI.Windows.DryIoc;
|
||||
using Artemis.UI.Windows.Providers.Input;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Threading;
|
||||
using Ninject;
|
||||
using DryIoc;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.UI.Windows;
|
||||
|
||||
public class App : Application
|
||||
{
|
||||
private StandardKernel? _kernel;
|
||||
private IContainer? _container;
|
||||
private bool _shutDown;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -33,8 +33,8 @@ public class App : Application
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
_kernel = ArtemisBootstrapper.Bootstrap(this, new WindowsModule());
|
||||
Program.CreateLogger(_kernel);
|
||||
_container = ArtemisBootstrapper.Bootstrap(this, new WindowsModule());
|
||||
Program.CreateLogger(_container);
|
||||
RxApp.MainThreadScheduler = AvaloniaScheduler.Instance;
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
@@ -45,14 +45,14 @@ public class App : Application
|
||||
return;
|
||||
|
||||
ArtemisBootstrapper.Initialize();
|
||||
_applicationStateManager = new ApplicationStateManager(_kernel!, desktop.Args);
|
||||
RegisterProviders(_kernel!);
|
||||
_applicationStateManager = new ApplicationStateManager(_container!, desktop.Args);
|
||||
RegisterProviders(_container!);
|
||||
}
|
||||
|
||||
private void RegisterProviders(StandardKernel standardKernel)
|
||||
private void RegisterProviders(IContainer container)
|
||||
{
|
||||
IInputService inputService = standardKernel.Get<IInputService>();
|
||||
inputService.AddInputProvider(standardKernel.Get<WindowsInputProvider>());
|
||||
IInputService inputService = container.Resolve<IInputService>();
|
||||
inputService.AddInputProvider(container.Resolve<InputProvider>(serviceKey: WindowsInputProvider.Id));
|
||||
}
|
||||
|
||||
private bool FocusExistingInstance()
|
||||
|
||||
@@ -10,7 +10,7 @@ using Artemis.UI.Windows.Utilities;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Threading;
|
||||
using Ninject;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Windows;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ApplicationStateManager
|
||||
{
|
||||
private const int SM_SHUTTINGDOWN = 0x2000;
|
||||
|
||||
public ApplicationStateManager(IKernel kernel, string[] startupArguments)
|
||||
public ApplicationStateManager(IContainer container, string[] startupArguments)
|
||||
{
|
||||
StartupArguments = startupArguments;
|
||||
IsElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
@@ -26,19 +26,19 @@ public class ApplicationStateManager
|
||||
Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
|
||||
Core.Utilities.RestartRequested += UtilitiesOnRestartRequested;
|
||||
|
||||
// On Windows shutdown dispose the kernel just so device providers get a chance to clean up
|
||||
// On Windows shutdown dispose the IOC container just so device providers get a chance to clean up
|
||||
if (Application.Current?.ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime)
|
||||
controlledApplicationLifetime.Exit += (_, _) =>
|
||||
{
|
||||
RunForcedShutdownIfEnabled();
|
||||
|
||||
// Dispose plugins before disposing the kernel because plugins might access services during dispose
|
||||
kernel.Get<IPluginManagementService>().Dispose();
|
||||
kernel.Dispose();
|
||||
// Dispose plugins before disposing the IOC container because plugins might access services during dispose
|
||||
container.Resolve<IPluginManagementService>().Dispose();
|
||||
container.Dispose();
|
||||
};
|
||||
|
||||
// Inform the Core about elevation status
|
||||
kernel.Get<ICoreService>().IsElevated = IsElevated;
|
||||
container.Resolve<ICoreService>().IsElevated = IsElevated;
|
||||
}
|
||||
|
||||
public string[] StartupArguments { get; }
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using Artemis.Core.DryIoc;
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared.Providers;
|
||||
using Artemis.UI.Windows.Providers;
|
||||
using Artemis.UI.Windows.Providers.Input;
|
||||
using DryIoc;
|
||||
|
||||
namespace Artemis.UI.Windows.DryIoc;
|
||||
|
||||
public class WindowsModule : IModule
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Load(IRegistrator builder)
|
||||
{
|
||||
builder.Register<ICursorProvider, CursorProvider>(Reuse.Singleton);
|
||||
builder.Register<IGraphicsContextProvider, GraphicsContextProvider>(Reuse.Singleton);
|
||||
builder.Register<IUpdateProvider, UpdateProvider>(Reuse.Singleton);
|
||||
builder.Register<IAutoRunProvider, AutoRunProvider>();
|
||||
builder.Register<InputProvider, WindowsInputProvider>(serviceKey: WindowsInputProvider.Id);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using Artemis.Core.Providers;
|
||||
using Artemis.UI.Shared.Providers;
|
||||
using Artemis.UI.Windows.Providers;
|
||||
using Ninject.Modules;
|
||||
|
||||
namespace Artemis.UI.Windows.Ninject;
|
||||
|
||||
public class WindowsModule : NinjectModule
|
||||
{
|
||||
#region Overrides of NinjectModule
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Load()
|
||||
{
|
||||
Kernel!.Bind<ICursorProvider>().To<CursorProvider>().InSingletonScope();
|
||||
Kernel!.Bind<IGraphicsContextProvider>().To<GraphicsContextProvider>().InSingletonScope();
|
||||
Kernel!.Bind<IUpdateProvider>().To<UpdateProvider>().InSingletonScope();
|
||||
Kernel!.Bind<IAutoRunProvider>().To<AutoRunProvider>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.ReactiveUI;
|
||||
using Ninject;
|
||||
using DryIoc;
|
||||
using Serilog;
|
||||
|
||||
namespace Artemis.UI.Windows;
|
||||
@@ -41,8 +41,8 @@ internal class Program
|
||||
.UseReactiveUI();
|
||||
}
|
||||
|
||||
public static void CreateLogger(IKernel kernel)
|
||||
public static void CreateLogger(IContainer container)
|
||||
{
|
||||
Logger = kernel.Get<ILogger>().ForContext<Program>();
|
||||
Logger = container.Resolve<ILogger>().ForContext<Program>();
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ public class WindowsInputProvider : InputProvider
|
||||
RawInputDevice.RegisterDevice(HidUsageAndPage.Mouse, RawInputDeviceFlags.InputSink, _sponge.Handle.Handle);
|
||||
}
|
||||
|
||||
public static Guid Id { get; } = new("6737b204-ffb1-4cd9-8776-9fb851db303a");
|
||||
|
||||
|
||||
#region Overrides of InputProvider
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ public class UpdateProvider : IUpdateProvider, IDisposable
|
||||
{
|
||||
if (windowOpen)
|
||||
{
|
||||
bool update = await _windowService.ShowDialogAsync<UpdateDialogViewModel, bool>(("channel", channel));
|
||||
bool update = await _windowService.ShowDialogAsync<UpdateDialogViewModel, bool>(channel);
|
||||
if (update)
|
||||
await RunInstaller(channel, false);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user