Plugins - Gave each plugin its own child Ninject kernel

Plugins - Added support for validation in VMs
This commit is contained in:
Robert committed 2020-09-21 16:21:32 +02:00
1 parent 411fa82313
commit c306bf9487
18 files changed
+132 -36

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
using System;
using Artemis.Core;
using Artemis.UI.Stylet;
using FluentValidation;
using Ninject.Extensions.Conventions;
using Ninject.Modules;
using Stylet;
namespace Artemis.UI.Ninject
{
public class PluginUIModule : NinjectModule
{
public PluginUIModule(PluginInfo pluginInfo)
{
PluginInfo = pluginInfo ?? throw new ArgumentNullException(nameof(pluginInfo));
}
public PluginInfo PluginInfo { get; }
public override void Load()
{
Bind(typeof(IModelValidator<>)).To(typeof(FluentValidationAdapter<>));
Kernel.Bind(x =>
{
x.From(PluginInfo.Assembly)
.SelectAllClasses()
.InheritedFrom<IValidator>()
.BindAllInterfaces();
});
}
}
}
-1
View File
@@ -14,7 +14,6 @@ using Stylet;
namespace Artemis.UI.Ninject
{
// ReSharper disable once InconsistentNaming
public class UIModule : NinjectModule
{
public override void Load()
@@ -10,16 +10,14 @@ namespace Artemis.UI.Screens.Modules
{
public class ModuleRootViewModel : Conductor<Screen>.Collection.OneActive
{
private readonly IKernel _kernel;
private readonly IModuleVmFactory _moduleVmFactory;
public ModuleRootViewModel(Module module, IModuleVmFactory moduleVmFactory, IKernel kernel)
public ModuleRootViewModel(Module module, IModuleVmFactory moduleVmFactory)
{
DisplayName = module?.DisplayName;
Module = module;
_moduleVmFactory = moduleVmFactory;
_kernel = kernel;
}
public Module Module { get; }
@@ -47,7 +45,7 @@ namespace Artemis.UI.Screens.Modules
var module = new ConstructorArgument("module", Module);
var displayName = new ConstructorArgument("displayName", DisplayName);
var viewModel = (ModuleViewModel) _kernel.Get(moduleTab.Type, module, displayName);
var viewModel = (ModuleViewModel) Module.PluginInfo.Kernel.Get(moduleTab.Type, module, displayName);
Items.Add(viewModel);
}
}
@@ -60,7 +60,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
// Find the BaseLayerBrush parameter, it is required by the base constructor so its there for sure
var brushParameter = constructors.First().GetParameters().First(p => typeof(BaseLayerBrush).IsAssignableFrom(p.ParameterType));
var argument = new ConstructorArgument(brushParameter.Name, layerBrush);
var viewModel = (BrushConfigurationViewModel) _kernel.Get(configurationViewModel.Type, argument);
var viewModel = (BrushConfigurationViewModel) layerBrush.PluginInfo.Kernel.Get(configurationViewModel.Type, argument);
_windowManager.ShowDialog(new LayerBrushSettingsWindowViewModel(viewModel));
}
@@ -86,7 +86,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Tree
var effectParameter = constructors.First().GetParameters().First(p => typeof(BaseLayerEffect).IsAssignableFrom(p.ParameterType));
var argument = new ConstructorArgument(effectParameter.Name, layerEffect);
var viewModel = (EffectConfigurationViewModel) _kernel.Get(configurationViewModel.Type, argument);
var viewModel = (EffectConfigurationViewModel) layerEffect.PluginInfo.Kernel.Get(configurationViewModel.Type, argument);
_windowManager.ShowDialog(new LayerEffectSettingsWindowViewModel(viewModel));
}
catch (Exception e)
@@ -23,7 +23,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
public class PluginSettingsViewModel : PropertyChangedBase
{
private readonly IDialogService _dialogService;
private readonly IKernel _kernel;
private readonly ILogger _logger;
private readonly IPluginService _pluginService;
private readonly ISnackbarMessageQueue _snackbarMessageQueue;
@@ -33,7 +32,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
private PluginInfo _pluginInfo;
public PluginSettingsViewModel(Plugin plugin,
IKernel kernel,
ILogger logger,
IWindowManager windowManager,
IDialogService dialogService,
@@ -43,7 +41,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
Plugin = plugin;
PluginInfo = plugin.PluginInfo;
_kernel = kernel;
_logger = logger;
_windowManager = windowManager;
_dialogService = dialogService;
@@ -96,7 +93,7 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
var pluginParameter = constructors.First().GetParameters().First(p => typeof(Plugin).IsAssignableFrom(p.ParameterType));
var plugin = new ConstructorArgument(pluginParameter.Name, Plugin);
var viewModel = (PluginConfigurationViewModel) _kernel.Get(configurationViewModel.Type, plugin);
var viewModel = (PluginConfigurationViewModel) PluginInfo.Kernel.Get(configurationViewModel.Type, plugin);
_windowManager.ShowDialog(new PluginSettingsWindowViewModel(viewModel, Icon));
}
catch (Exception e)
+19 -1
View File
@@ -1,6 +1,8 @@
using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.DefaultTypes.DataModel.Display;
using Artemis.UI.DefaultTypes.DataModel.Input;
using Artemis.UI.Ninject;
using Artemis.UI.PropertyInput;
using Artemis.UI.Services.Interfaces;
using Artemis.UI.Shared.Services;
@@ -11,14 +13,19 @@ namespace Artemis.UI.Services
{
private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService;
private readonly IPluginService _pluginService;
private bool _registeredBuiltInDataModelDisplays;
private bool _registeredBuiltInDataModelInputs;
private bool _registeredBuiltInPropertyEditors;
public RegistrationService(IDataModelUIService dataModelUIService, IProfileEditorService profileEditorService)
public RegistrationService(IDataModelUIService dataModelUIService, IProfileEditorService profileEditorService, IPluginService pluginService)
{
_dataModelUIService = dataModelUIService;
_profileEditorService = profileEditorService;
_pluginService = pluginService;
LoadPluginModules();
pluginService.PluginLoaded += PluginServiceOnPluginLoaded;
}
public void RegisterBuiltInDataModelDisplays()
@@ -63,6 +70,17 @@ namespace Artemis.UI.Services
_registeredBuiltInPropertyEditors = true;
}
private void PluginServiceOnPluginLoaded(object? sender, PluginEventArgs e)
{
e.PluginInfo.Kernel.Load(new[] { new PluginUIModule(e.PluginInfo) });
}
private void LoadPluginModules()
{
foreach (var pluginInfo in _pluginService.GetAllPluginInfo())
pluginInfo.Kernel.Load(new[] { new PluginUIModule(pluginInfo) });
}
}
public interface IRegistrationService : IArtemisUIService