Skip to content

CmdPal: Refactoring DI, Logging, and Extension Services#45437

Draft
michaeljolley wants to merge 15 commits intomainfrom
dev/mjolley/served-fresh
Draft

CmdPal: Refactoring DI, Logging, and Extension Services#45437
michaeljolley wants to merge 15 commits intomainfrom
dev/mjolley/served-fresh

Conversation

@michaeljolley
Copy link
Contributor

@michaeljolley michaeljolley commented Feb 5, 2026

IMPORTANT: This is a draft for a reason. You do not want to unintentionally make this real. Let's be honest, you probably don't want this real intentionally.

This is a freaking huge PR. In it we:

  • Refactor our usage of Dependency Injection to support not passing the service provider through a property on the App (ala App.Current.Services). Rather, services and models are injected into their requesting classes & controls via their constructor.
  • In previous versions, logging was handled in 3 different ways. With the new DI in place, all logging uses the .NET Microsoft.Extensions.Logging ILogger interface and a logger is injected into anything that might need to log something.
  • Modified how extensions are loaded. Rather than loading built-ins in the TopLevelCommandManager and, from there, loading 3P extensions in a combination of the TLCM and the ExtensionsService, we now register IExtensionServices and TLCM uses any that are provided to load extensions & commands. This includes a new BuiltInExtensionService and WinRTExtensionService to load built-ins and 3P extension respectively. In the future, we hope to extend this to support extensions written in other languages, ala JsonRPCExtensionService.
  • Added a new PersistenceService to be the backer of all services that need to persist data (e.g. SettingsService, AppStateService, PersonalizationService). It provides consolidated and generic methods for saving and loading persisted objects in JSON.
  • Removes .Core. All those viewmodels, etc. are now moved to either the Common, UI, or UI.ViewModels projects.

michaeljolley and others added 14 commits January 26, 2026 15:52
- Move project from Core/ subfolder to cmdpal/ root
- Update namespace from Microsoft.CmdPal.Core.Common to Microsoft.CmdPal.Common
- Update all project references and using statements
- Update solution files (PowerToys.slnx, CommandPalette.slnf)
…wModels

- Move all source files from Core.ViewModels to UI.ViewModels
- Update namespace from Microsoft.CmdPal.Core.ViewModels to Microsoft.CmdPal.UI.ViewModels
- Remove Core.ViewModels project from solution files
- Update all using statements in dependent projects
- Delete the Core folder which is now empty
- Extract persistence logic into PersistenceService
- Add AppStateService to manage app state
- Add SettingsService to manage settings
- Add JsonSerializationContext for AOT-compatible JSON
- Add EscapeKeyBehavior and MonitorBehavior enums
UI.ViewModels:
- CommandSettingsViewModel: Add ILogger injection
- CommandItemViewModel: Add ILogger with LoggerMessage methods
- ContextMenuViewModel: Add ILogger injection
- ExtensionObjectViewModel: Add Logger property with NullLogger default
- ShellViewModel: Replace CoreLogger calls with LoggerMessage methods
- UpdateCommandBarMessage: Remove logging from interface default method

UI helpers/services:
- WallpaperHelper: Add ILogger injection with LoggerMessage methods
- LocalKeyboardListener: Add ILogger injection with LoggerMessage methods
- ImageProvider: Add ILogger injection with LoggerMessage methods
- ThemeService: Add ILogger injection with LoggerMessage methods

Note: UI project migration is partial - XAML code-behind files still use static Logger
- Update all ViewModels to receive SettingsService via DI
- Implement IDisposable pattern for proper event cleanup
- Add App.Services property for DI access where needed
- Restore GetProviderSettings/GetGlobalFallbacks to SettingsModel
- Fix CommandProviderWrapper and TopLevelCommandManager logging
- Update all Settings pages to use SettingsService
- Add DefaultAppExtensionHost to replace CommandPaletteHost.Instance
- Add parameterless constructors for XAML-instantiated types
- Fix various ILogger injection issues throughout UI layer

[LoggerMessage(
Level = LogLevel.Warning,
Message = "Unrecognized target for shell navigation: {paramter}")]

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

paramter is not a recognized word. (unrecognized-spelling)
[LoggerMessage(
Level = LogLevel.Warning,
Message = "Unrecognized target for shell navigation: {paramter}")]
partial void Log_UnrecognizedShellNavigationTargetWarning(object paramter);

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

paramter is not a recognized word. (unrecognized-spelling)
@jiripolasek
Copy link
Collaborator

Holy squirrel!
image

@jiripolasek jiripolasek added the Product-Command Palette Refers to the Command Palette utility label Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants