command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

Make GetValueForHandlerParameter public

Open rsking opened this issue 3 years ago • 3 comments

If we are now required to write extension methods to allow for injected parameters (from beta 4), and get the values for the IValueDescriptors, having GetValueForHandlerParameter to be public, or an extension method would be useful. At this stage I am copying in the implementation into each project to facilitate this.

https://github.com/dotnet/command-line-api/blob/eaad2347f04f6a467d0ac02793bc4ed1d64889ca/src/System.CommandLine/Handler.cs#L11

rsking avatar Jun 20 '22 23:06 rsking

If the problem you're trying to solve is specific to dependency injection, another option is the one described here: https://github.com/dotnet/command-line-api/issues/1750#issuecomment-1152707726

Any thoughts on this approach?

jonsequitur avatar Jun 20 '22 23:06 jonsequitur

I was using something like that to get IHost, but was using context.Console, and context.GetCancellationToken() to get the IConsole and CancellationToken, which is not available directly from using the BindingBase<>.

It appears that we could use that to the IConsole, but how would we get the CancellationToken?

rsking avatar Jun 21 '22 00:06 rsking

Bind.FromServiceProvider<CancellationToken>() and Bind.FromServiceProvider<IConsole>() should work.

jonsequitur avatar Jun 21 '22 16:06 jonsequitur