Skip to content

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

Closed
wants to merge 23 commits into from
Closed

Explicit parameter binding #1018

wants to merge 23 commits into from

Conversation

KathleenDollard
Copy link
Contributor

Significant updates to binding so method binding and model binding use the same logic and same code paths.

Draft due to rebase issues.

@KathleenDollard KathleenDollard changed the title Explicit binding 4 Explicit parameter binding Aug 9, 2020
@@ -5,6 +5,7 @@ namespace System.CommandLine.Binding
{
public class BoundValue
{
// ?? Why have an internal constructor on a public readonly class?
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@brettfo brettfo changed the base branch from master to main August 19, 2020 19:52
@KathleenDollard
Copy link
Contributor Author

Closing in favor of non-draft one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants