Refactor CompareCommand to use proper dependency injection #29
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.
📋 Overview
This PR refactors the
CompareCommandclass to use proper dependency injection patterns, eliminating the service locator anti-pattern and improving code quality.🎯 Problem Solved
The original issue was that namespace mappings from JSON configuration files were not being applied. Investigation revealed that the root cause was improper dependency injection patterns where services were being resolved repeatedly through
GetRequiredServicecalls.✅ Changes Made
Core Refactoring
IExitCodeManager exitCodeManagerparameterIGlobalExceptionHandler exceptionHandlerparameterGetRequiredServicecalls in favor of constructor injectionSupporting Changes
ConfigureServicesmethod public for testing accessibilityDependencyInjectionTests.cswith 13 test methodsTest Updates
CreateCompareCommand()helper🧪 Test Results
All existing functionality is preserved and fully tested.
🏗️ Architecture Improvements
📂 Files Modified
src/DotNetApiDiff/Commands/CompareCommand.cssrc/DotNetApiDiff/Commands/TypeRegistrar.cssrc/DotNetApiDiff/Program.cstests/DotNetApiDiff.Tests/Integration/DependencyInjectionTests.cs(new)tests/DotNetApiDiff.Tests/Commands/CompareCommandTests.cstests/DotNetApiDiff.Tests/Commands/CompareCommandErrorTests.cstests/DotNetApiDiff.Tests/Commands/CompareCommandFilteringTests.cs🔄 Next Steps
With the DI architecture properly implemented, the next phase will be to investigate the original namespace mapping configuration issue to ensure JSON configuration mappings are correctly applied to the API comparison logic.
✅ Ready to Merge
Related to issue #28