Refactor Context: add IContext interface and register Context/IContext via DI - #256
Merged
Merged
Conversation
…er, improve thread safety, update docs Co-authored-by: michaelbeale-IL <63321611+michaelbeale-IL@users.noreply.github.com>
…update app startup Co-authored-by: michaelbeale-IL <63321611+michaelbeale-IL@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor Context class to use dependency injection
Refactor Context: add IContext interface and register Context/IContext via DI
Feb 22, 2026
michaelbeale-IL
approved these changes
Feb 22, 2026
- Context singleton now always uses the root IServiceProvider, avoiding issues with scoped providers by introducing GetRootProvider. - Added AddACATServices as an alias for AddACATCoreModules for clearer service registration. - Added null check in GetWidgetTypeFullName to prevent exceptions when _widgetTypeCollection is null.
michaelbeale-IL
marked this pull request as ready for review
February 23, 2026 15:50
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.
Contextwas a static-only class with no DI registration, requiring all consumers to callContext.AppXXXdirectly and manually assignContext.ServiceProviderat startup.Changes
New
IContextinterface (PanelManagement/IContext.cs)Mirrors the full static
ContextAPI as instance members — all manager properties, configuration properties, and utility methods — so consumers can injectIContextand switch from static calls without renaming anything.ContextimplementsIContextContext(IServiceProvider)constructor that sets the staticContext.ServiceProvider, wiring up DI on first resolutionIContextinterface implementations delegating to static members — zero behavior change for existingContext.AppXXXcallersDI registration (
ServiceCollectionExtensions.cs)New
AddContextService()registersIContextandContextas singletons. The factory (new Context(provider)) also configuresContext.ServiceProvider, so the existingResolveManager<T>fallback path continues to work. Included automatically viaAddACATCoreModules().Application startup (
ACATApp,ACATTalk)Replaced manual
Context.ServiceProvider = ...assignment with resolvingIContextfrom the container.Tests (
ContextDependencyInjectionTests.cs)Three new tests:
IContextresolves from DI, resolving it auto-configuresContext.ServiceProvider, andContext/IContextshare the same singleton instance.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.