Skip to content

[feature/10.0] Move binding logic to descriptors #8126

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

Open
wants to merge 6 commits into
base: feature/10.0
Choose a base branch
from

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Apr 18, 2025

This is in preparation for using the configuration binding source generator, which needs the concrete type of the settings object to be available at the Bind callsite. We have that type available in the descriptors, so that seems like a natural place to do it. This change replaces the generic descriptor types with concrete ones that use the specific settings types.

@sbomer sbomer marked this pull request as ready for review April 18, 2025 22:36
@sbomer sbomer requested a review from a team as a code owner April 18, 2025 22:36
@sbomer sbomer requested a review from jander-msft April 18, 2025 22:36
@sbomer sbomer changed the title Move binding logic to descriptors [feature/10.0] Move binding logic to descriptors Apr 18, 2025
@@ -73,6 +75,20 @@ public ICollectionRuleAction Create(IProcessInfo processInfo, BaseRecordOptions
}
}

internal sealed class CallbackActionDescriptor : ICollectionRuleActionDescriptor
Copy link
Member

Choose a reason for hiding this comment

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

I assume that these cannot be handled by a single generic class because the configuration source generator wouldn't be able to intercept the Bind call? Because if it could, I think all of these could be collapsed into one class.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right, the source generator can't intercept the call if it's made on a generic parameter.

{
services.AddSingleton<TFactory>();
services.AddSingleton<CollectionRuleActionFactoryProxy<TFactory, TOptions>>();
services.AddSingleton<ICollectionRuleActionDescriptor, CollectionRuleActionDescriptor<TFactory, TOptions>>(sp => new CollectionRuleActionDescriptor<TFactory, TOptions>(actionName));
services.AddSingleton<ICollectionRuleActionDescriptor, TDescriptor>(sp => new TDescriptor());
Copy link
Member

Choose a reason for hiding this comment

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

Do the descriptors actually need to be explicitly constructed? Couldn't service registration just do this for us e.g. services.AddSingleton<ICollectionRuleActionDescriptor, TDescriptor>(). Same question for the other descriptor registrations. If not, you can also remove the new() constraint on TDescriptor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed to let DI construct it for us, removed the new constraint.

- Don't construct descriptors explicitly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants