Added "Try" Methods and Predicate to Configuration Service#59
Merged
mdwigley merged 1 commit intoenterlucent:mainfrom Sep 3, 2025
mdwigley:issue#58-mdwigley
Merged
Added "Try" Methods and Predicate to Configuration Service#59mdwigley merged 1 commit intoenterlucent:mainfrom mdwigley:issue#58-mdwigley
mdwigley merged 1 commit intoenterlucent:mainfrom
mdwigley:issue#58-mdwigley
Conversation
mdwigley
added a commit
that referenced
this pull request
Sep 10, 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.
Description
This change introduces safe "Try" style registration and unregistration methods to the IConfigService interface and its implementation in ConfigService. The new methods (
TryRegisterConfigandTryUnregsterConfig) allow clients to attempt configuration registration and unregistration without exceptions, returning a boolean to indicate success. Additionally, a predicate methodIsConfigRegisteredwas added to check if a configuration type is already registered. The ConfigService class also gained a static helper method,GetInstance, for dependency-injection based construction. Furthermore, base classes for configuration providers were refactored for better separation, and null-handling behavior was improved in FileConfigService to prevent setting null on collection properties.Related Issue
Motivation and Context
The existing registration and unregistration operations throw exceptions on failure, which can complicate client error handling and reduce API usability. Adding safe "Try" methods simplifies client interaction by providing non-throwing options with clear success feedback. The predicate method enables clients to verify registration state before attempting changes. The DI-friendly static construction helper eases integration into dependency injection pipelines. These additions enhance robustness, clarity, and developer experience across the configuration service.
How Has This Been Tested?
The changes were tested with unit tests covering registration and unregistration both in normal and failure scenarios, ensuring the "Try" methods correctly return success status without throwing exceptions. Predicate checks were validated for correct presence reporting of registered types. The static DI construction was tested by initializing the ConfigService with a service collection in sample applications. Refactored provider base class functionality was verified to maintain existing behavior. Null handling in FileConfigService was tested to confirm collections are not set to null erroneously.
Screenshots (if appropriate):
Types of changes
Checklist: