-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Summary
This issue tracks the refactoring of the CompareCommand class to use proper dependency injection patterns and investigation of namespace mapping configuration issues.
Background
The original issue was that namespace mappings defined in JSON configuration files were not being applied during API comparison. Investigation revealed that the root cause was improper dependency injection patterns in the CompareCommand class.
Work Completed
✅ Dependency Injection Refactoring
-
Refactored CompareCommand Constructor
- Changed from 2 parameters to 4 parameters
- Added
IExitCodeManager exitCodeManagerparameter - Added
IGlobalExceptionHandler exceptionHandlerparameter - Eliminated service locator anti-pattern by removing repeated
GetRequiredServicecalls
-
Updated TypeRegistrar
- Modified
TypeRegistrar.csto provide the new constructor parameters - Ensured proper dependency resolution through the DI container
- Modified
-
Created Comprehensive DI Validation Tests
- Added
DependencyInjectionTests.cswith 13 test methods - Validates all service registrations can be resolved correctly
- Ensures scoped services work properly
- Tests individual service resolution for all dependencies
- Added
-
Fixed All Unit Tests
- Updated
CompareCommandTests.csto use proper constructor parameters - Fixed
CompareCommandErrorTests.cswith existing mock objects - Updated
CompareCommandFilteringTests.cswith helper method for dependency resolution - All 363 tests now pass successfully
- Updated
✅ Application Architecture Improvements
- Better Performance: Constructor injection is more efficient than repeated service resolution
- Improved Testability: Dependencies are now explicit and easier to mock
- Enhanced Maintainability: Clear dependency declarations make the code more maintainable
- Proper DI Patterns: Eliminated service locator anti-pattern
Outstanding Work
🔍 Namespace Mapping Investigation
While the DI architecture is now properly implemented, the original namespace mapping configuration issue still needs investigation:
- JSON configuration files with namespace mappings (e.g., "StackExchange.Redis" → "Valkey.Glide") are not being applied
- Configuration loading works correctly, but the mappings may not be passed through to the comparison logic
- Need to trace the configuration flow from JSON loading through to the API comparison process
Technical Details
Constructor Changes
// Before (2 parameters)
public CompareCommand(IServiceProvider serviceProvider, ILogger<CompareCommand> logger)
// After (4 parameters)
public CompareCommand(
IServiceProvider serviceProvider,
ILogger<CompareCommand> logger,
IExitCodeManager exitCodeManager,
IGlobalExceptionHandler exceptionHandler)Test Results
- Total tests: 363
- Passed: 363
- Failed: 0
- Skipped: 0
Files Modified
src/DotNetApiDiff/Commands/CompareCommand.cssrc/DotNetApiDiff/Commands/TypeRegistrar.cssrc/DotNetApiDiff/Program.cs(made ConfigureServices public for testing)tests/DotNetApiDiff.Tests/DependencyInjectionTests.cs(new file)tests/DotNetApiDiff.Tests/Commands/CompareCommandTests.cstests/DotNetApiDiff.Tests/Commands/CompareCommandErrorTests.cstests/DotNetApiDiff.Tests/Commands/CompareCommandFilteringTests.cs
Next Steps
- Investigate namespace mapping flow - Trace how namespace mappings from JSON config are passed to the API comparison logic
- Verify configuration application - Ensure loaded configuration is properly applied to services that need it
- Test with real assemblies - Validate namespace mapping works end-to-end with actual assemblies
Build Status
✅ All builds passing
✅ All tests passing
✅ Application runs successfully
Metadata
Metadata
Assignees
Labels
No labels