Repository navigation
Clarify IOptionsSnapshot performance characteristics and pipeline recomputation (Fixes #53890) - #56662
Open
Manish-1kumar wants to merge 1 commit into
Conversation
…computation (Fixes dotnet#53890)
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The guidance misstates monitor recomputation triggers by omitting explicit cache invalidation and needs to exclude scope-dependent options pipelines from monitor recommendations to avoid dependency-lifetime failures.
2 open issues
What changed in this PR
Clarifies IOptionsSnapshot<TOptions> performance in the .NET options-pattern guide, addressing #53890.
Changes:
- Explains per-scope pipeline execution and its potential impact on HTTP request latency.
- Adds guidance for choosing options interfaces and capturing monitor values for consistent per-scope access.
| File | Description |
|---|---|
docs/core/extensions/options.md |
Adds performance considerations, options-selection guidance, and an updated article date. |
Review effort: Balanced
| To select the right options abstraction for your scenario: | ||
|
|
||
| - **Static configuration**: If your configuration never changes after application startup, use <xref:Microsoft.Extensions.Options.IOptions`1>. It is a singleton service whose value is computed once for the entire application lifetime. | ||
| - **Reloadable configuration with high throughput**: If you need to observe configuration updates but want to avoid re-evaluating options on every request scope, use <xref:Microsoft.Extensions.Options.IOptionsMonitor`1>. `IOptionsMonitor` is a singleton service that caches options instances and only recomputes them when the underlying configuration source fires a change token notification. |
|
|
||
| - **Static configuration**: If your configuration never changes after application startup, use <xref:Microsoft.Extensions.Options.IOptions`1>. It is a singleton service whose value is computed once for the entire application lifetime. | ||
| - **Reloadable configuration with high throughput**: If you need to observe configuration updates but want to avoid re-evaluating options on every request scope, use <xref:Microsoft.Extensions.Options.IOptionsMonitor`1>. `IOptionsMonitor` is a singleton service that caches options instances and only recomputes them when the underlying configuration source fires a change token notification. | ||
| - **Consistent scope snapshots from an options monitor**: If your application requires a value that does not change during the execution of a single request, but you want to avoid per-scope recomputation, consider capturing <xref:Microsoft.Extensions.Options.IOptionsMonitor`1.CurrentValue> once at the start of the scope (such as in middleware) or registering a scoped service that resolves the current value from `IOptionsMonitor<TOptions>`. |
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.

Fixes #53890
Summary of Changes