-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Detailed Description
This feature proposes the addition of "Try" style registration and unregistration methods, as well as a registration-checking predicate, to the IConfigService interface and its implementations. The new TryRegisterConfig, TryUnregsterConfig, and IsConfigRegistered methods would provide safe ways to register and unregister configuration types, returning a boolean to indicate success instead of throwing exceptions. Additionally, a helper for static DI-based instantiation (e.g., GetInstance(IServiceCollection, AppConfig)) is proposed for easier integration in DI scenarios. The changes would enhance usability, code clarity, and error handling around configuration service interactions.
Context
Currently, the registration and unregistration methods for configuration types throw exceptions on errors, which can complicate error handling and reduce API clarity. There is also no simple way to check if a configuration type is already registered. Adding "Try" methods and an IsConfigRegistered predicate would enable safer, cleaner client code and easier testing. The static construction helper improves integration with dependency injection, streamlining setup for applications using the config service.
Possible Implementation
- Add
bool TryRegisterConfig(Type configType, IConfigServiceParams configParams)and related overloads to IConfigService, implemented to catch and suppress exceptions, returning false on failure. - Add
bool TryUnregsterConfig(Type configType, Token? token)and overloads to IConfigService for safe unregistration. - Add
bool IsConfigRegistered(Type configType)to check if a config type is registered. - Implement these in the core ConfigService class accordingly.
- Provide a static
GetInstance(IServiceCollection services, AppConfig appConfig)method to facilitate DI initialization. - Refactor provider classes (e.g., FileConfigService, UserFileConfigService) to inherit from a more appropriate base class if necessary for better separation of concerns.
Related Issues
- None
Target Platform(s)
- All platforms
Affected Components (optional)
PlugHub.Shared/Interfaces/Services/Configuration/IConfigServicePlugHub/Services/Configuration/ConfigServicePlugHub/Services/Configuration/Providers/FileConfigServicePlugHub/Services/Configuration/Providers/UserFileConfigService
Metadata
Metadata
Assignees
Labels
Type
Projects
Status