Skip to content

Command argument injection stopped working in 2.0.0-beta1.21308.1 #1368

Open
@ba32107

Description

@ba32107

Hi,

I have an application that is set up like this. My command:

public class DeleteCommand : Command
        {
            [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
            public class Input
            {
                public string Repository { get; set; }
                public string ObjectId { get; set; }
            }

            public DeleteCommand() : base("delete", "Deletes a file from the storage.")
            {
                AddArgument(new Argument<string>("repository", "The repository to delete the file from"));
                AddArgument(new Argument<string>("objectId", "The ID of the object to delete"));
            }
        }

My handler (HandlerBase is irrelevant for this issue):

public class DeleteHandler : HandlerBase
    {
        [UsedImplicitly]
        public Commands.DeleteCommand.Input Input { get; set; }

        public DeleteHandler(IDataStorageClient dataStorageClient, ILogger<DeleteHandler> logger)
            : base(dataStorageClient, null, logger)
        {
        }

        protected override async Task PerformActionAsync()
        {
            Logger.LogDebug(
                $"Deleting from repository '{Input.Repository}' with object ID '{Input.ObjectId}'...");

            await DataStorageClient.DeleteObjectAsync(Input.Repository, Input.ObjectId);

            Logger.LogDebug("Delete successful");
        }

And Program.cs (I've omitted some details for easier readability):

var parser = new CommandLineBuilder(Commands.BuildRootCommand())
                    .UseHelp()
                    .UseTypoCorrections()
                    .UseParseErrorReporting()
                    .UseVersionOption()
                    .UseHost(_ => Host.CreateDefaultBuilder(args), hostBuilder =>
                    {
                            .ConfigureServices(serviceCollection =>
                            {
                                serviceCollection
                                    .AddSingleton<IFileSystem>(new FileSystem())
                                    .AddSingleton(serviceProvider =>
                                    {
                                        // configure global args...
                                    });
                            })
                            .UseCommandHandler<Commands.DeleteCommand, DeleteHandler>();
                    })
                    .Build();

This works great in 2.0.0-beta1.21216.1 - the Input class is injected into DeleteHandler without an issue. However if I bump to version 2.0.0-beta1.21308.1, it doesn't work anymore. Input is not injected anymore.

I tried comparing the two versions but I couldn't find the tag for the newer version.

Is this a bug, or intended functionality? If the latter, then how can I easily get the command inputs in my handler class?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions