-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config refactor - fix struct/class
T
nullable ref issues, and allow…
… "raw" access to `ConfigurationResult` (#5715) ## Summary of changes - Fixes bugs related to nullable reference types when used with generics - Allow retrieving the "raw" `ConfigurationResult<>` directly from a configuration builder. ## Reason for change The first issue is the method `T? GetAs<T>(key)` doesn't behave as we (previously) believed. If you call `GetAs<int>(somekey)` we previously were expecting it to return `null`, but it doesn't - the best you can do is return `default` i.e. 0. There's no technical way around this limitation AFAIK other than having separate methods, or having methods that are guaranteed non-null returning. So in this PR we have both. Additionally, there are some cases where it's useful to provide access to the "raw" `ConfigurationResut<T>`. One example is shown in this PR where the security settings want to know both whether the value was set _and_ what the value is, while also providing a default. It will also be useful in subsequent PRs for refactoring the OTel config. ## Implementation details - Expose additional `Get*Result()` methods on `ConfigurationBuilder`, e.g. `GetBoolResult()` returns a `StructConfigurationResultWithKey<bool>`, `GetStringResult()` returns a `ClassConfigurationResultWithKey<bool>`, - You can use this to inspect the result to see if the key was present (for example) - You can then call `WithDefault(T default)` on this to get the correct value (and record the default in telemetry correctly) ## Test coverage Mostly a refactor, should be covered by existing tests ## Other details <!-- Fixes #{issue} --> This is part of a big stack of config refactoring PRs: - #5713 - #5714 - #5715 (this PR) - #5716 - #5717 <!--⚠️ Note: where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. -->
- Loading branch information
1 parent
7b8b43d
commit bd869dc
Showing
4 changed files
with
210 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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