dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.21k stars 5.86k forks source link

Provide an example using Options Pattern, OptionsValidator source code generator and NativeAOT. #38524

Open Abdragiz opened 9 months ago

Abdragiz commented 9 months ago

Type of issue

Missing information

Description

The article says that using OptionsValidator results in smoother creation of AOT-compatible applications, but there is no example of AOT-compatible Options Pattern configuration. The only example of an Options Pattern configuration is

builder.services
      .AddOptions<SettingsOptions>()
      .Bind(Configuration.GetSection(SettingsOptions.ConfigurationSectionName))

And this example doesn't work with NativeAOT analyzers because the Bind method has RequiresDynamicCode and RequiresUnreferencedCode attributes.

Page URL

https://learn.microsoft.com/en-us/dotnet/core/extensions/options-validation-generator

Content source URL

https://github.com/dotnet/docs/blob/main/docs/core/extensions/options-validation-generator.md

Document Version Independent Id

0775474e-7773-d061-ed21-0a360c8466b1

Article author

@tarekgh

Metadata

Abdragiz commented 9 months ago

Found about <EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator> from What's new -> .NET 8 -> Configuration-binding source generator. I think information about this property should be included Options Pattern docs.

tarekgh commented 9 months ago

@Abdragiz we are planning to have a new doc for the configuration source generator which should include whatever you are asking for. I don't mind adding something to the options doc if you like. are you interested to submit a PR for it?

Abdragiz commented 9 months ago

@tarekgh, I'm sorry, but English is not my native language, i don't think i am able to submit PR.