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

Adddresses #408 - Expand Microsoft.Extentions.Hosting... #409

Merged
merged 2 commits into from
Jan 9, 2021

Conversation

hellfirehd
Copy link
Contributor

No description provided.

@hellfirehd
Copy link
Contributor Author

What do I do to get all the checks passing? The details links are less than helpful.

@cbcrouse
Copy link
Contributor

@hellfirehd I was reviewing the issue in the pipeline and the error message says Invoke-WebRequest : The operation has timed out. If you look at line 36 in the docs/generate.ps1 script, you'll see that it's making a request to the NuGet API.

I ran the line from the script myself and it worked fine.

image

My assumption here is that NuGet's API was temporarily unavailable or the Azure DevOps had a hiccup. I bet it will pass on a re-run. You can probably add/remove a space to your branch and push the changes to get the trigger to go off again if unable to re-trigger manually.

Copy link
Owner

@natemcmaster natemcmaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making a PR to address #408. I have a few questions below.

Also, before merging, I'd like to see the addition of some kind of test coverage. If you're not sure how to write some tests for this, let me know and we can thinking through some options together.

Thanks!
-Nate

Comment on lines +164 to +188
configure ??= app => { };
var state = new CommandLineState(args);
hostBuilder.Properties[typeof(CommandLineState)] = state;
hostBuilder.ConfigureServices(
(context, services)
=>
{
services
.TryAddSingleton<StoreExceptionHandler>();
services
.TryAddSingleton<IUnhandledExceptionHandler>(provider => provider.GetRequiredService<StoreExceptionHandler>());
services
.AddSingleton<IHostLifetime, CommandLineLifetime>()
.TryAddSingleton(PhysicalConsole.Singleton);
services
.AddSingleton(provider =>
{
state.SetConsole(provider.GetService<IConsole>());
return state;
})
.AddSingleton<CommandLineContext>(state)
.AddSingleton<ICommandLineService, CommandLineService<TApp>>();
services
.AddSingleton(configure);
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be largely a duplication of

configure ??= app => { };
var exceptionHandler = new StoreExceptionHandler();
var state = new CommandLineState(args);
hostBuilder.Properties[typeof(CommandLineState)] = state;
hostBuilder.ConfigureServices(
(context, services)
=>
{
services
.TryAddSingleton<IUnhandledExceptionHandler>(exceptionHandler);
services
.AddSingleton<IHostLifetime, CommandLineLifetime>()
.TryAddSingleton(PhysicalConsole.Singleton);
services
.AddSingleton(provider =>
{
state.SetConsole(provider.GetService<IConsole>());
return state;
})
.AddSingleton<CommandLineContext>(state)
.AddSingleton<ICommandLineService, CommandLineService<TApp>>();
services
.AddSingleton(configure);
});
. Did you consider ways to eliminate or reduce the duplication?

Comment on lines +6 to +12
using System;
using System.Runtime.ExceptionServices;
using System.Threading;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using McMaster.Extensions.Hosting.CommandLine.Internal;
using Microsoft.Extensions.DependencyInjection;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit-pick: can you move usings to the top of the file instead of nesting inside the namespace? Sorry VS doesn't provide a way to enforce this style consistently :-/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. I think you can set that in .editorconfig

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion! I've added to editorconfig.

Comment on lines +31 to +40
var exceptionHandler = host.Services.GetService<StoreExceptionHandler>();
var state = host.Services.GetRequiredService<CommandLineState>();

await host.RunAsync(cancellationToken);

if (exceptionHandler?.StoredException != null)
{
ExceptionDispatchInfo.Capture(exceptionHandler.StoredException).Throw();
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to duplicate

using var host = hostBuilder.Build();
await host.RunAsync(cancellationToken);
if (exceptionHandler.StoredException != null)
{
ExceptionDispatchInfo.Capture(exceptionHandler.StoredException).Throw();
}
return state.ExitCode;
. Same question as above. Could we reduce the duplication? Maybe the implementation of the existing Task<int> RunCommandLineApplicationAsync method could be replaced with two chained calls to new API you are proposing in this PR.

@hellfirehd
Copy link
Contributor Author

I'm not going to be able to get back to this anytime soon. If anyone else wants to take a shot at it, please go ahead.

@cbcrouse
Copy link
Contributor

cbcrouse commented Jan 8, 2021

@hellfirehd I'll give this a shot and pick up where you left off.

@natemcmaster natemcmaster changed the base branch from main to feature/408 January 9, 2021 21:57
@natemcmaster
Copy link
Owner

@cbcrouse thanks! I'm going to merge this PR to a feature/408 branch so we can keep @hellfirehd's work noted. We can merge that branch to main with your PR on top of it.

@natemcmaster natemcmaster merged commit 47d1194 into natemcmaster:feature/408 Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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