Skip to content

Comments

Refactor Context class: wire static manager properties to DI via ResolveManager#251

Merged
michaelbeale-IL merged 2 commits intomasterfrom
copilot/refactor-context-class
Feb 21, 2026
Merged

Refactor Context class: wire static manager properties to DI via ResolveManager#251
michaelbeale-IL merged 2 commits intomasterfrom
copilot/refactor-context-class

Conversation

Copy link
Contributor

Copilot AI commented Feb 21, 2026

Context.ResolveManager<T>() existed as a DI-aware helper but was never called — all static manager properties read directly from their Lazy<T> singletons, making Context.ServiceProvider have no effect on property resolution.

Changes

Context.cs

  • All 9 AppXxx static manager properties now delegate to ResolveManager<T>() instead of reading _xxxManager.Value directly — DI instances are used automatically when ServiceProvider is set, with transparent singleton fallback when not
  • Fixed TOCTOU race in both ResolveManager<T>() and GetManager<TInterface>() by capturing ServiceProvider to a local before use
  • Added missing XML doc on AppCommandManager
// Before: bypassed DI entirely
public static ActuatorManager AppActuatorManager
    => _actuatorManager.Value;

// After: DI-first, singleton fallback
public static ActuatorManager AppActuatorManager
    => ResolveManager<ActuatorManager>(() => _actuatorManager.Value);

No changes required at any of the 383+ Context.App* call sites — DI takes effect the moment Context.ServiceProvider is assigned.

Documentation

  • DEPENDENCY_INJECTION_GUIDE.md: updated Context section to describe DI-aware property resolution and the adapter pattern rationale
  • ACAT_MODERNIZATION_PLAN.md: added Phase 2 DI Infrastructure section reflecting completed state of issues Setup Service Container #209Extension Loading with DI #216 (service container, Context refactor, interface extraction, factory pattern)
Original prompt

This section details on the original issue you should resolve

<issue_title>Refactor Context Class</issue_title>
<issue_description>Remove static dependencies from Context class and inject services.

Acceptance Criteria:

  • Context class redesigned to use DI
  • All Context consumers updated
  • Static references removed or minimized
  • Proper lifetime management for Context
  • Tests updated
  • No breaking changes to external APIs

Technical Approach:

  • Inject required managers into Context
  • Provide Context through IServiceProvider
  • Update all Context.AppXXX references
  • Consider Context as scoped service

Risk Areas:

  • Many places reference Context statically
  • May need gradual migration approach
  • Consider adapter pattern for legacy code

Files to Modify:

  • Libraries/ACATCore/Utility/Context.cs
  • All files that use Context (search for 'Context.App')

Epic: Dependency Injection Infrastructure

Estimated Effort: 5 days

</issue_description>

<agent_instructions>Make sure to review all progress from task #209 - and update any relevant documentation on progress made with this task.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…er, improve thread safety, update docs

Co-authored-by: michaelbeale-IL <63321611+michaelbeale-IL@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor Context class to remove static dependencies Refactor Context class: wire static manager properties to DI via ResolveManager Feb 21, 2026
@michaelbeale-IL michaelbeale-IL marked this pull request as ready for review February 21, 2026 21:55
@michaelbeale-IL michaelbeale-IL merged commit 8916c20 into master Feb 21, 2026
2 checks passed
@michaelbeale-IL michaelbeale-IL deleted the copilot/refactor-context-class branch February 21, 2026 21: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

Development

Successfully merging this pull request may close these issues.

Refactor Context Class

2 participants