You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a specific problem? Or an existing feature?
The AddStrategy extension methods take a ResilienceStrategyOptions options argument, which gets validated using DataAnnotations. This makes the method incompatible with trimming and native AOT, and it is annotated as such:
Callers who want to use this API in a trim compatible way need to define an empty class derived from ResilienceStrategyOptions and suppress the warning from calling this API.
Describe the solution you'd like
We should add overloads to these AddStrategy methods that are trim compatible, and don't take an options argument. Similar to the AddPipeline methods.
[RequiresUnreferencedCode(Constants.OptionsValidation)]
public static TBuilder AddStrategy<TBuilder>(this TBuilder builder, Func<StrategyBuilderContext, ResilienceStrategy> factory, ResilienceStrategyOptions options)
where TBuilder : ResiliencePipelineBuilderBase {}
+public static TBuilder AddStrategy<TBuilder>(this TBuilder builder, Func<StrategyBuilderContext, ResilienceStrategy> factory) + where TBuilder : ResiliencePipelineBuilderBase {}
[RequiresUnreferencedCode(Constants.OptionsValidation)]
public static ResiliencePipelineBuilder AddStrategy(
this ResiliencePipelineBuilder builder, Func<StrategyBuilderContext, ResilienceStrategy<object>> factory,
ResilienceStrategyOptions options) {}
+public static ResiliencePipelineBuilder AddStrategy(+ this ResiliencePipelineBuilder builder, Func<StrategyBuilderContext, ResilienceStrategy<object>> factory) {}
[RequiresUnreferencedCode(Constants.OptionsValidation)]
public static ResiliencePipelineBuilder<TResult> AddStrategy<TResult>(
this ResiliencePipelineBuilder<TResult> builder, Func<StrategyBuilderContext, ResilienceStrategy<TResult>> factory,
ResilienceStrategyOptions options) {}
+ public static ResiliencePipelineBuilder<TResult> AddStrategy<TResult>(+ this ResiliencePipelineBuilder<TResult> builder, Func<StrategyBuilderContext, ResilienceStrategy<TResult>> factory) {}
This seems to be actually a bug, at least in the documentation. The options parameter in the ResiliencePipelineBuilderExtensions.AddStrategy methods is described like this:
The options associated with the strategy. If none are provided the default instance of ResilienceStrategyOptions is created.
So one would expect the parameter already to be optional. There is the ´EmptyOptions´ class, but it's internal, so I need to copy it if I don't need any options for my strategy.
This seems to be actually a bug, at least in the documentation. The options parameter in the ResiliencePipelineBuilderExtensions.AddStrategy methods is described like this:
The options associated with the strategy. If none are provided the default instance of ResilienceStrategyOptions is created.
So one would expect the parameter already to be optional. There is the ´EmptyOptions´ class, but it's internal, so I need to copy it if I don't need any options for my strategy.
These are incorrect docs, thanks for noticing. Both new API and fixed docs are addressed in #2068.
Is your feature request related to a specific problem? Or an existing feature?
The
AddStrategy
extension methods take aResilienceStrategyOptions options
argument, which gets validated using DataAnnotations. This makes the method incompatible with trimming and native AOT, and it is annotated as such:Polly/src/Polly.Core/ResiliencePipelineBuilderExtensions.cs
Lines 68 to 70 in 82474bf
Polly/src/Polly.Core/ResiliencePipelineBuilderExtensions.cs
Lines 90 to 93 in 82474bf
Polly/src/Polly.Core/ResiliencePipelineBuilderExtensions.cs
Lines 114 to 117 in 82474bf
Callers who want to use this API in a trim compatible way need to define an empty class derived from
ResilienceStrategyOptions
and suppress the warning from calling this API.Describe the solution you'd like
We should add overloads to these
AddStrategy
methods that are trim compatible, and don't take anoptions
argument. Similar to theAddPipeline
methods.Additional context
This is being used by Microsoft.Extensions.Http.Resilience here:
dotnet/extensions#4962 (comment)
Adding this API would make the caller simpler. It wouldn't need to declare an empty class, and suppress the trim warning.
The text was updated successfully, but these errors were encountered: