Conversation
…nt proper DI Co-authored-by: yulin0629 <2434581+yulin0629@users.noreply.github.com>
Co-authored-by: yulin0629 <2434581+yulin0629@users.noreply.github.com>
…ix project Co-authored-by: yulin0629 <2434581+yulin0629@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] @yulin0629/PJ2017031_RB/files/RoyalBase/Controllers/API/YPOrderPickingOperationController.cs
@yulin0629/PJ2017031_RB/files/RoyalBase/App_Start/UnityConfig.cs
@yulin0629/PJ2017031_RB/files/RoyalBase/Service/YP/YPOrderPickingOperationService.cs
@yulin062...
Fix Unity StackOverflow issue in YPOrderPickingOperation API caused by circular dependency
Jul 11, 2025
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.
Problem
The
/api/YPOrderPickingOperation/GetListAPI endpoint was causing StackOverflow exceptions due to a circular dependency in the Unity dependency injection container configuration.Root Cause
The issue was caused by a self-referencing dependency in the Unity container setup:
Execution Flow of the Bug
/api/YPOrderPickingOperation/GetListIYPOrderPickingOperationServicefrom Unity containerYPOrderPickingOperationServiceinstanceIYPOrderPickingOperationServiceinjectionYPOrderPickingOperationServiceinstanceSolution
✅ Fixed Unity Configuration
Eliminated the circular dependency by introducing proper external dependencies:
✅ Fixed Service Constructor
Key Changes
IDataRepository,ILogger)ContainerControlledLifetimeManagerfor singleton behaviorFiles Modified
RoyalBase/App_Start/UnityConfig.cs- Main fix: Updated Unity container configurationRoyalBase/Service/YP/YPOrderPickingOperationService.cs- Constructor fix: Corrected dependency injectionRoyalBase/Service/YP/IYPOrderPickingOperationService.cs- Service interface definitionRoyalBase/Controllers/API/YPOrderPickingOperationController.cs- API controller implementationTesting & Validation
✅ Validation Results
/api/YPOrderPickingOperation/GetListreturns data)Test Files Added
RoyalBase/Tests/UnityConfigTests.cs- Comprehensive Unity container validationValidationTest.cs- Simplified validation logicvalidate_fix.sh- Automated verification scriptImpact
Before: API calls → StackOverflow exception → Application crash
After: API calls → Normal operation → Data returned successfully
The Unity StackOverflow issue has been completely resolved with minimal, surgical changes focused exclusively on the dependency injection configuration. No business logic was altered, ensuring zero functional impact while eliminating the critical stability issue.
Prevention
Added validation mechanisms in
UnityConfig.ValidateContainer()to detect circular dependencies during application startup, preventing similar issues in the future.💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.