Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate native AOT compatibility #1110

Closed
Tracked by #1302
martincostello opened this issue Apr 11, 2023 · 4 comments · Fixed by #1414
Closed
Tracked by #1302

Investigate native AOT compatibility #1110

martincostello opened this issue Apr 11, 2023 · 4 comments · Fixed by #1414
Assignees
Labels
aot Relates to native AoT support enhancement v8 Issues related to the new version 8 of the Polly library.
Milestone

Comments

@martincostello
Copy link
Member

Is your feature request related to a specific problem? Or an existing feature? Please describe.

ASP.NET Core 8 is making investments in supporting native AOT scenarios. In the case of APIs using Polly, we should ensure that we are also native AOT-friendly.

Describe your proposed or preferred solution:

Polly is fully usable with native AOT (or with known, documented, limitations).

Potential changes we may have to make include:

  • annotations for trimming
  • changes to any use of reflection

Describe any alternative options you've considered:

Do nothing.

Any additional info?

ASP.NET Core blog post

@martincostello martincostello added this to the v8.0.0 milestone Apr 11, 2023
@martincostello martincostello self-assigned this Apr 11, 2023
@martintmk
Copy link
Contributor

Currently, as far as I know the Polly.Core only uses reflection for options validation:

https://github.com/App-vNext/Polly/blob/main/src/Polly.Core/Utils/ValidationHelper.cs

However, .NET folks are planning to introduce a generator for options validation:
dotnet/runtime#85475

This can help us make Polly V8 reflection-free. The only downside is that the generator works with Microsoft.Extensions.Options package and I think we shouldn't have this dependency in Polly.Core. Ideally, the generator should also work with only System.ComponentModel.Annotations.

cc @geeknoid

@geeknoid
Copy link
Contributor

The .NET 8 generator currently depends on Microsoft.Extensions.Options. This is because the geneator looks at the IValidateOptions type to determine the type to implement validation for.

Do you have any ideas how the generator could work without taking a dependency on Microsoft.Extensions.Options?

@martintmk
Copy link
Contributor

@geeknoid Just thinking out loud. We could use this syntax:

[OptionsValidator]
public partial class RetryStrategyOptions
{
    // Can generate inner RetryStrategyOptionsValidator here 
}

internal static partial class PollyValidators
{
   // just implements the method
   [OptionsValidator]
   public static partial IEnumerable<ValidationResult> ValidateRetryOptions(RetryStrategyOptions options);
}

Essentially, we just need something that we pass the options instance to and it returns us the list of ValidationResult. If the list is empty, then there are no errors. Ideally, we would just reference the generator package as a build-time dependency without any other changes. It could recognize our internal OptionsValidatorAttribute and just output the code.

That way, the Polly stays dependency free on .NET3.1+ runtimes.

@geeknoid
Copy link
Contributor

@martintmk I like those ideas. Not sure if I'll have time to put that in, but I'll try...

@martincostello martincostello added the v8 Issues related to the new version 8 of the Polly library. label Jun 16, 2023
@martincostello martincostello added the aot Relates to native AoT support label Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aot Relates to native AoT support enhancement v8 Issues related to the new version 8 of the Polly library.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants