Skip to content

Create source generator for configuration binding - #82179

Merged
layomia merged 7 commits into
dotnet:mainfrom
layomia:add-configbinder-src-generator
Mar 16, 2023
Merged

Create source generator for configuration binding#82179
layomia merged 7 commits into
dotnet:mainfrom
layomia:add-configbinder-src-generator

Conversation

@layomia

@layomialayomia commented Feb 15, 2023

Copy link
Copy Markdown
Contributor

@layomialayomia added this to the 8.0.0 milestone Feb 15, 2023
@layomialayomia self-assigned this Feb 15, 2023
@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details
Author:layomia
Assignees:layomia
Labels:

area-Extensions-Configuration

Milestone:8.0.0

@layomia
layomia requested review from jeffhandley and removed request for jeffhandleyFebruary 15, 2023 18:30
@layomialayomia added the NO-REVIEW Experimental/testing PR, do NOT review it label Feb 15, 2023
@layomia
layomiaforce-pushed the add-configbinder-src-generator branch 5 times, most recently from d27439a to 6c9f2edCompareFebruary 16, 2023 20:19
@layomia
layomiaforce-pushed the add-configbinder-src-generator branch from 6c9f2ed to 2020a35CompareFebruary 21, 2023 04:14
@layomia

Copy link
Copy Markdown
ContributorAuthor

We have the green light from API review to proceed with this implementation. Still need to resolve CI failures but it's ready for a first look.

@layomialayomia removed the NO-REVIEW Experimental/testing PR, do NOT review it label Feb 21, 2023
@layomialayomia changed the title Create source generator for ConfigurationBinderCreate source generator for configuration bindingFeb 22, 2023
(node, _) => node is InvocationExpressionSyntax invocation,
(context, cancellationToken) => new BinderInvocationOperation(context, cancellationToken));

IncrementalValueProvider<(KnownTypeData, ImmutableArray<BinderInvocationOperation>)> inputData = compilationData.Combine(inputCalls.Collect());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to call Combine here? Assuming you have an application with 500 BinderInvocationOperation locations, then changing just one would result in all 500 of them being aggregated and recalculated.

Assuming there is no strong performance reason behind consolidating one parser for all operations, I would recommend keeping these independent as an IncrementalValueSProvider<(KnownTypeData, BinderInvocationOperation)>. IncrementalValuesProvider also has a RegisterSourceOutput which can be triggered independently for each of its components without forcing recalculation of the others.

namespace Microsoft.Extensions.Configuration.Binder.SourceGeneration
{
internal sealed record SourceGenerationSpec(
HashSet<TypeSpec> TypesForBindMethodGen,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 This was my solution:

DotNetAnalyzers/StyleCopAnalyzers@253d408

If there is a better solution I'm interested to know.

@layomia

layomia commented Mar 16, 2023

Copy link
Copy Markdown
ContributorAuthor

Thanks for reviewing this PR folks. I've opened issues to address feedback not resolved in this PR. They are linked above and also tracked by #79527. I'll merge this PR now to make preview 3 & because additional changes will require more review & churn. I believe the current implementation is viable for users to try as-is. W.r.t risk to the product caused by issues/bugs in the feature:

  • It is only available via referencing the NuGet package
  • It is opt-in via setting property <EnableMicrosoftExtensionsConfigurationBinderGenerator>true</EnableMicrosoftExtensionsConfigurationBinderGenerator>

Here are the follow up items I'll try to address in preview 3 (snaps on Monday 3/20, cc @carlossanlop):

@davidfowl

Copy link
Copy Markdown
Member

How do I enable the source generator?

@ViktorHofer

ViktorHofer commented Mar 20, 2023

Copy link
Copy Markdown
Member

How do I enable the source generator?

@davidfowl see layomi's comment above:

It is opt-in via setting property <EnableMicrosoftExtensionsConfigurationBinderGenerator>true</EnableMicrosoftExtensionsConfigurationBinderGenerator>

Make sure that the latest available Microsoft.Extensions.Configuration.Binder.nupkg is referenced (from the dotnet8 feed).

@ghostghost locked as resolved and limited conversation to collaborators May 13, 2023
@layomialayomia added the source-generator Indicates an issue with a source generator feature label May 17, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-Configurationsource-generatorIndicates an issue with a source generator feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

12 participants

@layomia@ViktorHofer@ericstj@davidfowl@krwq@sharwell@bollhals@stephentoub@eiriktsarpalis@am11@eerhardt@tarekgh