refactor(di): extract common validation and error handling patterns#298
Merged
Conversation
Extract duplicated validation and error handling code from service_container into reusable helper methods to improve maintainability: - Add check_frozen_for_registration() for frozen state validation - Add check_already_registered() for duplicate registration checks - Add invoke_factory_safe() for factory exception handling This eliminates duplicate patterns in: - register_factory_internal() and register_instance_internal() - singleton, transient, and scoped resolution branches All 111 tests pass, thread safety preserved. Closes #297
16 tasks
kcenon
added a commit
that referenced
this pull request
Apr 13, 2026
…298) Extract duplicated validation and error handling code from service_container into reusable helper methods to improve maintainability: - Add check_frozen_for_registration() for frozen state validation - Add check_already_registered() for duplicate registration checks - Add invoke_factory_safe() for factory exception handling This eliminates duplicate patterns in: - register_factory_internal() and register_instance_internal() - singleton, transient, and scoped resolution branches All 111 tests pass, thread safety preserved. Closes #297
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.
Summary
register_factory_internal()andregister_instance_internal()intocheck_frozen_for_registration()andcheck_already_registered()helper methodsinvoke_factory_safe()helper methodChanges Made
register_factory_internal()register_instance_internal()resolve_with_detection()invoke_factory_safe()calls (~6 lines)New Helper Methods
Test Plan
Closes #297