-
Notifications
You must be signed in to change notification settings - Fork 402
Explicit parameter binding #1018
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
Conversation
src/System.CommandLine.Tests/Binding/ModelBinderConstructorTests.cs
Outdated
Show resolved
Hide resolved
src/System.CommandLine.Tests/Binding/ModelBinderConstructorTests.cs
Outdated
Show resolved
Hide resolved
src/System.CommandLine.Tests/Binding/ModelBinderConstructorTests.cs
Outdated
Show resolved
Hide resolved
@@ -5,6 +5,7 @@ namespace System.CommandLine.Binding | |||
{ | |||
public class BoundValue | |||
{ | |||
// ?? Why have an internal constructor on a public readonly class? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want people to create instances of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not appear that BoundValue escape the context of System.CommandLine. I think we should deliberately consider the needs of any application models that need something other than to connect a ValueSource to a Option/Argument ahead of any evaluation. IOW, we may need this public in the future, but it does not appear that we need it public now.
This is probably part of a broader discussion of checking our public API surface.
{ | ||
public static class InvocationExtensions | ||
{ | ||
public static void BindParameter(this ICommandHandler handler, ParameterInfo param, Option option) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These shouldn't be necessary, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is needed, although it might not be in the right place. That extension method drives the following syntax:
handler.BindParameter(parameter, argument);
command.Handler = handler;
The handler is managed as an ICommandHandler, so putting the method on the interface isn't sensible due to the ParameterInfo/PropertyInfo. Thus, an extension method seemed the right approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or were you just expecting to always do it on the argument and this is on the option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think making ModelBindingCommandHandler
public makes more sense than extending the interface but throwing if it's the wrong implementation.
Closing in favor of non-draft one. |
Significant updates to binding so method binding and model binding use the same logic and same code paths.
Draft due to rebase issues.