Skip to content
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

Expand Microsoft.Extensions.Hosting support to allow work to be done prior to Run*Async() #408

Closed
hellfirehd opened this issue Nov 12, 2020 · 3 comments · Fixed by #409, #415 or #416
Closed
Assignees
Milestone

Comments

@hellfirehd
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I often have startup tasks that must be performed prior to running the console. I usually hang these off IHost so that they can create IServiceScope and benefit from the rest of the DI configuration.

var host = CreateHostBuilder(args).Build();
await host.StartServiceBusAsync("QueueName");
await host.RunAsync().ConfigureAwait(false);

However, you can't call .Buid() twice so that doesn't work with RunCommandLineApplicationAsync<T>().

Describe the solution you'd like
I want to be able to do this:

class Program
{
    static async Task<Int32> Main(String[] args)
    {
        var host = CreateHostBuilder(args).Build();

        await host.StartServiceBus("QueueName");

        return await host.RunCommandLineApplicationAsync<Program>();
    }

    public static IHostBuilder CreateHostBuilder(String[] args) =>
        Host.CreateDefaultBuilder(args)
            .UseCommandLineApplication<Program>(args)
            .ConfigureServices((hostContext, services) =>
            {
                /* SNIP */
            });
}

Describe alternatives you've considered
I looked at #134 and #185. They both wanted the same thing I do but it was early days and it appears they kind of fizzled.

I have a pull request ready to go that implements the above. I'd love for you to take a look at it!

hellfirehd added a commit to hellfirehd/CommandLineUtils that referenced this issue Nov 12, 2020
@natemcmaster natemcmaster linked a pull request Nov 30, 2020 that will close this issue
@natemcmaster natemcmaster added this to the 3.1.0 milestone Nov 30, 2020
@natemcmaster
Copy link
Owner

The proposal seems fine to me. Let's continue to iterate on the implementation together as proposed in #409

@cbcrouse
Copy link
Contributor

cbcrouse commented Jan 9, 2021

Hey @natemcmaster and @hellfirehd - I was able to address the issues of code duplication and missing tests. I've created another PR.

@hellfirehd your commits are still included in this, I just forked and cherry-picked.

@natemcmaster
Copy link
Owner

Resolved in #409, #415, and #416

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment