Repository navigation
Conversation
Core and Core.Windows cannot reference the app, so the app will register a resolver delegate here from a module initializer, the same pattern as SettingsAccess. TryGet returns null when no provider is set or the type is not registered; GetRequired throws with the missing type named. Adds a direct reference to Microsoft.Extensions.DependencyInjection.Abstractions 10.0.14, which Core already pulled in transitively via NCalc.Core. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Instance now asks ServiceAccess first and falls back to the existing lazy GetOrAdd instance, exposed internally as FallbackInstance. With no provider registered, behavior is unchanged. The app will register each Singleton-backed type with a factory returning FallbackInstance, so code that runs before and after the container exists sees the same object. Adds the class constraint, which every current use already satisfies. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AppServices builds one Microsoft.Extensions.DependencyInjection container, lazily, on first resolve. A module initializer only stores the delegate that reads it, so test discovery and design-time builds construct nothing. Registers SettingsService, HistoryService, TtsService, LanguageService and WebSearchUrlCatalog through a factory returning Singleton<T>.FallbackInstance, so every service is still constructed on first use, on the same thread, and Singleton<T>.Instance and the container return the same object in either order. ITextGrabSettings is transient over SettingsAccess.Current so swapping the settings resolver in tests is not cached. Adds one shared HttpClient. Adds the Microsoft.Extensions.DependencyInjection 10.0.14 package to the app. Co-Authored-By: Claude Opus 5.5 <[email protected]>
HotKeyIds, NumberOfRunningInstances and TextGrabIcon now live on an AppRuntimeState singleton registered in AppServices. App's properties of the same names forward to it, so no caller changes in this commit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replaces the three (App)App.Current casts in NotifyIconUtilities with the container's AppRuntimeState. RegisterHotKeys and UnregisterHotkeys took an App only to reach HotKeyIds, so they are now parameterless, and their callers in SettingsWindow, KeysSettings and App drop the App.Current casts that existed only to pass it in. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replaces the (App)App.Current cast used to close the tray icon when run-in-the-background is turned off. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replaces the App.Current cast in WindowUtilities.ShouldShutDown. The old guard only skipped the check when Current was not App, which never happens in the app; with default state the result is the same either way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds a constructor taking an HttpClient and moves the user-agent from the client's DefaultRequestHeaders onto each request, so a shared client is never modified. The Language settings page passes the container's HttpClient instead of creating a new client per download. The parameterless constructor still creates its own client. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Records that DI.Abstractions was already transitive in Core, that Tests adds four Singleton<LanguageService> uses, and why removing the SettingsWindow and KeysSettings casts meant changing the hotkey method signatures. Fixes the Tests.Core.Windows executable path in the v5 README. Co-Authored-By: Claude Opus 5.5 <[email protected]>
UnregisterHotkeys unregistered every ID but kept them in the list, and RegisterHotKeys always appends fresh IDs (HotKeyManager never reuses them). Each Settings open/close cycle therefore grew the list by a full set, and every later unregister re-sent the stale IDs to the message window. The list now holds only the IDs that are currently registered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
HotKeyManager took every ID from an ever-increasing counter, including for registrations that failed. RegisterHotKey only accepts application IDs up to 0xBFFF, so a long enough session of Settings open/close cycles would exhaust the range and every later registration would fail. A HotKeyIdPool now hands out the lowest free ID in 1..0xBFFF and takes IDs back on unregister and on failed registration. Hotkey presses are matched by key and modifiers, never by ID, so reuse does not change dispatch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
F1 now ends with the HotKeyIds and hotkey ID reuse fixes, so the row records 790bc4e instead of 0d53f5a. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase F1 of the v5 plan (docs/v5/F1-DI-Composition-Root.md): one
Microsoft.Extensions.DependencyInjectioncontainer built by the app. The existingSingleton<T>resolves through it without any of its 77 call sites changing, and without changing when any service is constructed. Also fixes two hotkey bugs found along the way.What changes
ServiceAccess(Core): static seam through which Core and Core.Windows reach the app's container.TryGet<T>returns null when no provider is registered or the type is unknown;GetRequired<T>throws and names the type.Singleton<T>.InstanceasksServiceAccessfirst, then falls back to the old lazy instance, now exposed internally asFallbackInstance. Behavior is unchanged when no provider is registered. Adds aclassconstraint, which every current use already meets.AppServices(app): a lazily builtServiceProvider. A[ModuleInitializer]only stores the delegate that reads it, so test discovery and design-time builds construct nothing.SettingsService,HistoryService,TtsService,LanguageServiceandWebSearchUrlCatalogare registered through a factory that returnsSingleton<T>.FallbackInstance. The container andSingleton<T>hand out the same object whichever is asked first, and each service is still built on first use, on the calling thread.ITextGrabSettingsis transient overSettingsAccess.Current, so tests that swap the settings resolver don't get a cached object.HttpClient, which recycles pooled connections every 2 minutes.AppRuntimeState.AppRuntimeStatenow ownsHotKeyIds,NumberOfRunningInstancesandTextGrabIcon.App's properties forward to it, and every(App)App.Current/App.Current is Appcast is replaced with a container lookup.NotifyIconUtilities.RegisterHotKeysandUnregisterHotkeystook anApponly to reachHotKeyIds, so they are now parameterless.TesseractGitHubFileDownloadercan take the sharedHttpClient. Its user-agent moved from the client's default headers onto each request, so a shared client is never modified.UnregisterHotkeysnow clearsHotKeyIds. Before, every Settings open/close cycle appended a full set of new IDs.HotKeyManagernow reuses freed IDs through aHotKeyIdPool(1–0xBFFF) instead of a counter that only grows. Long sessions could otherwise run out of the Win32 application ID range.Startup order is unchanged. The first
Singleton<T>.Instanceread, inApp's static init, builds the container immediately beforeSettingsServiceis constructed, on the same thread and at the same moment as before.New NuGet packages (please verify the MSIX build in Visual Studio)
Microsoft.Extensions.DependencyInjection10.0.14 inText-GrabMicrosoft.Extensions.DependencyInjection.Abstractions10.0.14 inText-Grab.Core. It was already transitive viaNCalc.Core, so no resolved version changes.Testing
dotnet build Tests/Tests.csproj -c Debug -p:Platform=x64Tests.Core.exeTests.Core.Windows.exeTierBoundaryTests3/3Tests.exeTests.exeexits 139 after printing its summary. This also happens ondev;TestHostInitializer.csdocuments it as the ARM64 graphics-driver teardown crash.New tests cover:
ServiceAccess, andSingleton<T>with and without a provider;Singleton<T>and the container returning the same instance in both resolution orders, on probe types no earlier test has touched;HotKeyIdsclearing andHotKeyIdPoolreuse and exhaustion.Hand checks on the unpackaged Debug build, in isolated automation profiles:
--windowlessand the Settings window behave the same as ondev.Still to check: the packaged (MSIX) build and first-run migration, in Visual Studio.
🤖 Generated with Claude Code