Repository navigation
Fix CLI + Remove CommonServiceLocator indirection - #128
Conversation
Refactor dependency injection indirection replacing CommonServiceLocator with a simple custom ServiceContainer class: - Removed references to CommonServiceLocator across multiple files. - Introduced a new ServiceContainer class for managing service registrations and retrievals. - Updated all instances where services were fetched using ServiceLocator to use the new ServiceContainer. - Removed the DependencyServiceLocator class and its associated tests. - Removed CommonServiceLocator package dependency - Added tests for the new ServiceContainer to ensure proper functionality.
There was a problem hiding this comment.
Pull request overview
This PR fixes the broken CLI startup caused by the removed/unclear service locator setup and simplifies the codebase by removing the CommonServiceLocator dependency and plugin-system indirection, replacing it with a lightweight static service container.
Changes:
- Introduce
ServiceContainerand migrate service resolution fromCommonServiceLocator.ServiceLocatortoServiceContainer.Get/Register. - Fix CLI by initializing required services (
Key2JoyManager.InitForClient) before parsing/running verbs. - Remove the plugin system (core plugin host/proxies, plugin projects, plugin UI, and related tests/docs).
Reviewed changes
Copilot reviewed 144 out of 155 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Support/Key2Joy.Tests/PluginHost/PluginHostTestBase.cs | Remove plugin-host test base (plugin system removed). |
| Support/Key2Joy.Tests/PluginHost/PluginHostRegistryAccessTests.cs | Remove plugin registry sandbox test. |
| Support/Key2Joy.Tests/PluginHost/PluginHostFileAccessTests.cs | Remove plugin file sandbox tests. |
| Support/Key2Joy.Tests/PluginHost/PluginHostCommonTests.cs | Remove basic plugin-host tests. |
| Support/Key2Joy.Tests/Key2Joy.Tests.csproj | Drop plugin host + test plugin project references. |
| Support/Key2Joy.Tests/Core/Util/ServiceContainerTests.cs | Add unit tests for new ServiceContainer. |
| Support/Key2Joy.Tests/Core/Util/DependencyServiceLocatorTests.cs | Remove tests for DependencyServiceLocator/CommonServiceLocator. |
| Support/Key2Joy.Tests/Core/Plugins/PluginSetTests.cs | Remove PluginSet tests (plugin system removed). |
| Support/Key2Joy.Tests/Core/Mapping/MappingProfileTests.cs | Switch config service registration to ServiceContainer. |
| Support/Key2Joy.Tests/Core/Mapping/MappingProfileLegacyTests.cs | Switch config service registration to ServiceContainer. |
| Support/Key2Joy.Tests/Core/Mapping/Actions/Scripting/PluginExposedMethodTests.cs | Remove plugin-exposed-method tests. |
| Support/Key2Joy.Tests/Core/Mapping/Actions/Scripting/LuaScriptActionTests.cs | Update references after plugin contract removals. |
| Support/Key2Joy.Tests/Core/Mapping/Actions/Scripting/JavascriptScriptActionTests.cs | Update references after plugin contract removals. |
| Support/Key2Joy.Tests/Core/Mapping/Actions/ActionsRepositoryTests.cs | Remove plugin-related imports/usage. |
| Support/Key2Joy.Tests/Core/LowLevelInput/SimulatedGamePad/SimulatedGamePadTests.cs | Switch XInput service setup to ServiceContainer. |
| Support/Key2Joy.Tests/Core/Key2JoyManagerTests.cs | Update InitSafely signature usage (no plugin set). |
| Support/Key2Joy.Tests/Core/Interop/Commands/CommandInfoTests.cs | Replace ServiceLocator usage with ServiceContainer. |
| Support/Key2Joy.Tests/Core/Config/Stubs/old-config.json | Remove enabled-plugins stub data. |
| Support/Key2Joy.Tests/Core/Config/Stubs/current-config.json | Remove enabled-plugins stub data. |
| Support/Key2Joy.Tests/Contracts/Plugins/Remoting/RemotePipeTests.cs | Remove remoting/pipe tests tied to plugin host. |
| Support/Key2Joy.Tests/Contracts/Mappings/Actions/ActionOptionsControl.cs | Remove plugin action options parity test. |
| Support/Key2Joy.Tests/BuildMarkdownDocs/Util/AssemblyHelperTests.cs | Remove plugin-assembly path test. |
| Support/Key2Joy.Tests/BuildMarkdownDocs/sample.xml | Remove plugin-related XML doc entries / update callback types. |
| Support/Key2Joy.Tests.Stubs/TestPlugin/RegistryAccessAction.cs | Remove test plugin action. |
| Support/Key2Joy.Tests.Stubs/TestPlugin/Plugin.cs | Remove test plugin entry type. |
| Support/Key2Joy.Tests.Stubs/TestPlugin/permissions.xml | Remove test plugin permissions file. |
| Support/Key2Joy.Tests.Stubs/TestPlugin/Key2Joy.Tests.Stubs.TestPlugin.csproj | Remove test plugin project. |
| Support/Key2Joy.Tests.Stubs/TestPlugin/FileAccessAction.cs | Remove test plugin action. |
| Support/Key2Joy.Tests.Stubs/TestPlugin/ExposedMethodsAction.cs | Remove test plugin scripting-exposed action. |
| Support/Key2Joy.Tests.Stubs/TestPlugin/CommonAction.cs | Remove test plugin action. |
| Support/CopyPlugin.bat | Remove plugin copy helper script. |
| Support/BuildMarkdownDocs/Util/AssemblyHelper.cs | Remove plugin directory probing logic. |
| Support/BuildMarkdownDocs/Members/FunctionMember.cs | Remove “IsPlugin” handling in docs member model. |
| Support/BuildMarkdownDocs/MarkdownService.cs | Remove plugin/non-plugin level modifier handling. |
| Support/BuildMarkdownDocs/DefaultTemplate.md | Remove plugin note block from docs template. |
| README.md | Formatting cleanup + remove plugin package reference in acknowledgements section. |
| Plugins/Key2Joy.Plugin.Midi/Plugin.cs | Remove Midi plugin entry (plugin system removed). |
| Plugins/Key2Joy.Plugin.Midi/permissions.xml | Remove plugin permissions file. |
| Plugins/Key2Joy.Plugin.Midi/Mapping/Actions/InputDeviceListenForEvent.cs | Remove plugin MIDI action. |
| Plugins/Key2Joy.Plugin.Midi/Mapping/Actions/InputDeviceGetAllAction.cs | Remove plugin MIDI action. |
| Plugins/Key2Joy.Plugin.Midi/Key2Joy.Plugin.Midi.csproj | Remove MIDI plugin project. |
| Plugins/Key2Joy.Plugin.HelloWorld/Plugin.cs | Remove HelloWorld plugin entry. |
| Plugins/Key2Joy.Plugin.HelloWorld/permissions.xml | Remove plugin permissions file. |
| Plugins/Key2Joy.Plugin.HelloWorld/Mapping/Actions/GetHelloWorldActionControl.xaml.cs | Remove plugin UI control. |
| Plugins/Key2Joy.Plugin.HelloWorld/Mapping/Actions/GetHelloWorldActionControl.xaml | Remove plugin UI XAML. |
| Plugins/Key2Joy.Plugin.HelloWorld/Mapping/Actions/GetHelloWorldAction.cs | Remove plugin action. |
| Plugins/Key2Joy.Plugin.HelloWorld/Key2Joy.Plugin.HelloWorld.csproj | Remove HelloWorld plugin project. |
| Plugins/Key2Joy.Plugin.Ffmpeg/Plugin.cs | Remove FFmpeg plugin entry. |
| Plugins/Key2Joy.Plugin.Ffmpeg/permissions.xml | Remove plugin permissions file. |
| Plugins/Key2Joy.Plugin.Ffmpeg/Mapping/Actions/AnimationFromImagesAction.cs | Remove FFmpeg plugin action. |
| Plugins/Key2Joy.Plugin.Ffmpeg/Key2Joy.Plugin.Ffmpeg.csproj | Remove FFmpeg plugin project. |
| Plugins/Key2Joy.Plugin.Ffmpeg/ffmpeg/x86/ffprobe.exe | Binary asset associated with removed FFmpeg plugin. |
| Plugins/Key2Joy.Plugin.Ffmpeg/ffmpeg/x86/ffmpeg.exe | Binary asset associated with removed FFmpeg plugin. |
| Plugins/Key2Joy.Plugin.Ffmpeg/ffmpeg/x64/ffprobe.exe | Binary asset associated with removed FFmpeg plugin. |
| Plugins/Key2Joy.Plugin.Ffmpeg/ffmpeg/x64/ffmpeg.exe | Binary asset associated with removed FFmpeg plugin. |
| Key2Joy.sln | Remove plugin/plugin-host projects from the solution. |
| Key2Joy.Gui/Program.cs | Remove plugin set plumbing; switch to ServiceContainer. |
| Key2Joy.Gui/PluginsForm.Designer.cs | Remove plugin management UI. |
| Key2Joy.Gui/PluginsForm.cs | Remove plugin management UI logic. |
| Key2Joy.Gui/PluginPermissionsForm.Designer.cs | Remove plugin permission confirmation UI. |
| Key2Joy.Gui/PluginPermissionsForm.cs | Remove plugin permission confirmation logic. |
| Key2Joy.Gui/PluginPermissionControl.resx | Remove plugin permission control resources. |
| Key2Joy.Gui/PluginPermissionControl.Designer.cs | Remove plugin permission control UI. |
| Key2Joy.Gui/PluginPermissionControl.cs | Remove plugin permission control logic. |
| Key2Joy.Gui/MappingForm.cs | Remove plugin-hosted options control path; use in-proc mapping controls only. |
| Key2Joy.Gui/Mapping/Triggers/TriggerControl.cs | Remove plugin-related imports. |
| Key2Joy.Gui/Mapping/Triggers/GamePad/GamePadButtonTriggerControl.cs | Switch IXInput resolution to ServiceContainer. |
| Key2Joy.Gui/Mapping/Actions/Input/GamePadTriggerActionControl.cs | Switch gamepad service resolution to ServiceContainer. |
| Key2Joy.Gui/Mapping/Actions/Input/GamePadStickActionControl.cs | Switch gamepad service resolution to ServiceContainer. |
| Key2Joy.Gui/Mapping/Actions/Input/GamePadActionControl.cs | Switch gamepad service resolution to ServiceContainer. |
| Key2Joy.Gui/Mapping/Actions/ActionPluginHostControl.Designer.cs | Remove plugin-host control wrapper UI. |
| Key2Joy.Gui/Mapping/Actions/ActionPluginHostControl.cs | Remove plugin-host control wrapper logic. |
| Key2Joy.Gui/Mapping/Actions/ActionControl.cs | Remove plugin-related imports. |
| Key2Joy.Gui/MainForm.cs | Replace service locator usage; remove plugin menu actions. |
| Key2Joy.Gui/MainForm_DeviceList.cs | Replace service locator usage for device discovery. |
| Key2Joy.Gui/ConfigForm.cs | Replace service locator usage for config state access. |
| Key2Joy.Cmd/Properties/launchSettings.json | Add launch profile for easier CLI debugging. |
| Key2Joy.Cmd/Program.cs | Fix CLI by calling Key2JoyManager.InitForClient() and using ServiceContainer. |
| Docs/Index.md | Remove plugin API entries from documentation index. |
| Docs/Api/Plugins/Midi/Midi.InputDeviceListenForEvent.md | Remove generated plugin API doc page. |
| Docs/Api/Plugins/Midi/Midi.InputDeviceGetAll.md | Remove generated plugin API doc page. |
| Docs/Api/Plugins/Ffmpeg/Ffmpeg.AnimationFromImages.md | Remove generated plugin API doc page. |
| Core/Key2Joy.PluginHost/Program.cs | Remove plugin host executable entrypoint. |
| Core/Key2Joy.PluginHost/PluginHost.cs | Remove sandbox/plugin host implementation. |
| Core/Key2Joy.PluginHost/NativeHandleContractInsulator.cs | Remove remoting/contract insulator. |
| Core/Key2Joy.PluginHost/Native.cs | Remove plugin host native helpers. |
| Core/Key2Joy.PluginHost/Key2Joy.PluginHost.csproj | Remove plugin host project. |
| Core/Key2Joy.PluginHost/App.config | Remove plugin host app config. |
| Core/Key2Joy.PluginHost/AllowedPermissionsWithDescriptions.cs | Remove plugin permission whitelist logic. |
| Core/Key2Joy.Core/Util/ServiceContainer.cs | Add new static service container (replaces CommonServiceLocator). |
| Core/Key2Joy.Core/Util/DependencyServiceLocator.cs | Remove CommonServiceLocator-based service locator. |
| Core/Key2Joy.Core/Plugins/PluginTriggerProxy.cs | Remove plugin proxy type. |
| Core/Key2Joy.Core/Plugins/PluginSet.cs | Remove plugin set loader and type buffering. |
| Core/Key2Joy.Core/Plugins/PluginLoadState.cs | Remove plugin load state model. |
| Core/Key2Joy.Core/Plugins/PluginHostProxy.cs | Remove plugin host proxy and type discovery. |
| Core/Key2Joy.Core/Plugins/PluginActionProxy.cs | Remove plugin action proxy. |
| Core/Key2Joy.Core/Plugins/IGetRealObject.cs | Remove plugin proxy helper interface. |
| Core/Key2Joy.Core/Plugins/ElementHostProxy.cs | Remove plugin UI host proxy. |
| Core/Key2Joy.Core/Mapping/Triggers/TriggersRepository.cs | Remove plugin-related imports. |
| Core/Key2Joy.Core/Mapping/Triggers/Mouse/MouseMoveTriggerListener.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Triggers/Mouse/MouseButtonTriggerListener.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Triggers/Keyboard/KeyboardTriggerListener.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Triggers/GamePad/GamePadTriggerTriggerListener.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Triggers/GamePad/GamePadStickTriggerListener.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Triggers/GamePad/GamePadButtonTriggerListener.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/MappingTypeHelper.cs | Simplify type-name resolution now that plugin proxies are removed. |
| Core/Key2Joy.Core/Mapping/MappingTypeFactory.cs | Move mapping factories into core mapping namespace; remove plugin factory subclass. |
| Core/Key2Joy.Core/Mapping/MappingProfile.cs | Replace config service access with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/JsonMappingAspectConverter.cs | Remove plugin-related imports. |
| Core/Key2Joy.Core/Mapping/Actions/Scripting/LuaScriptAction.cs | Remove plugin contract references. |
| Core/Key2Joy.Core/Mapping/Actions/Scripting/LuaIterator.cs | Remove plugin-related example from XML doc (plugin removed). |
| Core/Key2Joy.Core/Mapping/Actions/Scripting/JavascriptScriptAction.cs | Remove plugin contract references. |
| Core/Key2Joy.Core/Mapping/Actions/Scripting/ExposedMethod.cs | Remove plugin-exposed-method subclass. |
| Core/Key2Joy.Core/Mapping/Actions/Logic/SetTimeoutAction.cs | Remove plugin contract references. |
| Core/Key2Joy.Core/Mapping/Actions/Logic/SetIntervalAction.cs | Remove plugin contract references. |
| Core/Key2Joy.Core/Mapping/Actions/Input/GamePadTriggerAction.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Actions/Input/GamePadStickAction.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Actions/Input/GamePadResetAction.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Actions/Input/GamePadButtonAction.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Mapping/Actions/CoreAction.cs | Remove plugin-related import. |
| Core/Key2Joy.Core/Mapping/Actions/ActionsRepository.cs | Remove plugin-related import. |
| Core/Key2Joy.Core/LowLevelInput/SimulatedGamePad/SimulatedGamePadService.cs | Replace service locator usage with ServiceContainer. |
| Core/Key2Joy.Core/Key2JoyManager.cs | Remove plugin initialization; add InitForClient; migrate DI to ServiceContainer. |
| Core/Key2Joy.Core/Key2Joy.Core.csproj | Remove CommonServiceLocator/Mono.Cecil/plugin-host references. |
| Core/Key2Joy.Core/Config/IConfigManager.cs | Remove plugin enable/disable API from config contract. |
| Core/Key2Joy.Core/Config/ConfigState.cs | Remove EnabledPlugins config field. |
| Core/Key2Joy.Core/Config/ConfigManager.cs | Remove plugin enable/disable logic and checksum handling. |
| Core/Key2Joy.Contracts/Util/TypeConverter.cs | Move callback-related types from plugin namespace to mapping namespace. |
| Core/Key2Joy.Contracts/Plugins/SecurityOverride.cs | Remove plugin security override permission type. |
| Core/Key2Joy.Contracts/Plugins/Remoting/ViewContractConverter.cs | Remove plugin UI remoting helper. |
| Core/Key2Joy.Contracts/Plugins/Remoting/SubscriptionTicket.cs | Remove remoting subscription data type. |
| Core/Key2Joy.Contracts/Plugins/Remoting/SubscriptionRegistration.cs | Remove remoting subscription registration type. |
| Core/Key2Joy.Contracts/Plugins/Remoting/RemotePipe.cs | Remove remote pipe helper. |
| Core/Key2Joy.Contracts/Plugins/Remoting/RemoteEventSubscriberHost.cs | Remove plugin event pipe host. |
| Core/Key2Joy.Contracts/Plugins/Remoting/RemoteEventSubscriberClient.cs | Remove plugin event pipe client. |
| Core/Key2Joy.Contracts/Plugins/Remoting/RemoteEventSubscriber.cs | Remove plugin event subscription manager. |
| Core/Key2Joy.Contracts/Plugins/Remoting/RemoteEventHandler.cs | Remove plugin remote event handler types. |
| Core/Key2Joy.Contracts/Plugins/Remoting/PluginAssemblyResolver.cs | Remove plugin assembly resolver. |
| Core/Key2Joy.Contracts/Plugins/PluginTriggerInsulator.cs | Remove plugin trigger insulator. |
| Core/Key2Joy.Contracts/Plugins/PluginTrigger.cs | Remove plugin trigger base type. |
| Core/Key2Joy.Contracts/Plugins/PluginLoadException.cs | Remove plugin load exception type. |
| Core/Key2Joy.Contracts/Plugins/PluginException.cs | Remove plugin exception type. |
| Core/Key2Joy.Contracts/Plugins/PluginBase.cs | Remove plugin base class. |
| Core/Key2Joy.Contracts/Plugins/PluginActionInsulator.cs | Remove plugin action insulator. |
| Core/Key2Joy.Contracts/Plugins/PluginAction.cs | Remove plugin action base type. |
| Core/Key2Joy.Contracts/Plugins/IPluginUserControl.cs | Remove plugin UI contract. |
| Core/Key2Joy.Contracts/Plugins/IPluginHost.cs | Remove plugin host contract. |
| Core/Key2Joy.Contracts/Mapping/MappingControlRepository.cs | Remove plugin-related imports; keep in-proc mapping control buffering. |
| Core/Key2Joy.Contracts/Mapping/MappingControlFactory.cs | Move mapping control factories into contracts mapping namespace; drop plugin factory. |
| Core/Key2Joy.Contracts/Mapping/CallbackActionWrapper.cs | Move callback wrapper into Key2Joy.Contracts.Mapping namespace. |
| Core/Key2Joy.Contracts/Mapping/CallbackAction.cs | Move callback delegate into Key2Joy.Contracts.Mapping namespace. |
| Core/Key2Joy.Contracts/Mapping/Actions/IPluginActionOptionsControl.cs | Remove plugin-specific action options control interface. |
Files not reviewed (5)
- Key2Joy.Gui/MainForm.Designer.cs: Language not supported
- Key2Joy.Gui/Mapping/Actions/ActionPluginHostControl.Designer.cs: Language not supported
- Key2Joy.Gui/PluginPermissionControl.Designer.cs: Language not supported
- Key2Joy.Gui/PluginPermissionsForm.Designer.cs: Language not supported
- Key2Joy.Gui/PluginsForm.Designer.cs: Language not supported
Comments suppressed due to low confidence (2)
Core/Key2Joy.Core/Mapping/MappingTypeHelper.cs:6
MappingTypeHelper.csincludes several unusedusingdirectives (System.Linq,System.Text,System.Threading.Tasks). These aren’t needed anymore after removing the plugin/proxy logic and add noise to the file; please remove them to keep the compilation unit minimal and avoid warnings in stricter build configurations.
Core/Key2Joy.Core/Mapping/MappingTypeFactory.cs:6MappingTypeFactory.csnow pulls in several unused namespaces (System.Linq,System.Text,System.Threading.Tasks). Removing them will reduce noise and avoid warnings if the solution later enables warnings-as-errors.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This will be easier to review once #127 is approved and merged (see note in PR body). |
| }); | ||
|
|
||
| // Reader threads: continuously call Get while the writer is mutating the dictionary. | ||
| var readers = new Task[4]; |
There was a problem hiding this comment.
This test is dubious: it seems flaky, but I trust that it's here for a good reason 😌
There was a problem hiding this comment.
I had it built after Copilot reviewed and complained about possible race conditions. I must say I relied heavily on Copilot to prove the problem to me and had it write a failing test that I then fixed. If this test becomes a problem we can just remove it and wait for any problems to occur
abart27
left a comment
There was a problem hiding this comment.
The changes make sense - nice refactor!
Note
Given that I expected #127 to be merged, I merged it into branch this already. That saved me having to update code in the plugin system, that would've been removed anyway by that PR.
This will fix the CLI (fix #73)
Besides that this PR removes the dependency on the NuGet package CommonServiceLocator. Simply storing global instances in ServiceContainer, minorly simplifying the setup.