Skip to content

Use the registered IKeybindingService in KeybindingManager [patch] - #210

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/208-inject-keybinding-service
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/208-inject-keybinding-service

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #208

What changed

  • KeybindingManager now has a primary constructor (ICommandRegistry, IProfileManager, IKeybindingRepository, IKeybindingService). Because it has the most resolvable parameters, Microsoft.Extensions.DependencyInjection selects it, so manager.Keybindings is the IKeybindingService registered in the container. That covers both the default registration and a custom or decorated one. The analyzer (IDE0290) asked for a primary constructor, which is why the class was converted.
  • The existing three-argument constructor is kept for standalone use. It goes on creating a KeybindingService over the given registry and profile manager. The string dataDirectory constructor is unchanged.
  • KeybindingManagerFactory.CreateManager() passes the registered IKeybindingService when there is one.

Before this change, the container held two different keybinding services, even with the default AddKeybinding registration: the registered one and the one the manager created.

Tests

KeybindingServiceInjectionTests is new. It checks that manager.Keybindings is the same instance as the registered service in four cases: a custom registration, the default singleton registration, the scoped registration, and factory.CreateManager(). It also checks that the three-argument constructor still builds its own KeybindingService.

Without the fix, the four same-instance tests fail. With the fix, the full suite passes (334/334 on this branch) and Keybinding.sln builds with no warnings.


Generated by Claude Code

KeybindingManager always created its own KeybindingService, so a custom
or decorated IKeybindingService registered with the container never took
effect and the container held two keybinding services. The manager now
takes the service through its primary constructor, which dependency
injection selects, and KeybindingManagerFactory.CreateManager() passes
the registered one. The three-argument constructor still builds a
KeybindingService for standalone use.

Fixes #208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW49jMQ3NXp3nePHu2u
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit a72b360 into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/208-inject-keybinding-service branch November 4, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants