-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
Conversation
What do I do to get all the checks passing? The details links are less than helpful. |
@hellfirehd I was reviewing the issue in the pipeline and the error message says I ran the line from the script myself and it worked fine. 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. |
There was a problem hiding this 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
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); | ||
}); |
There was a problem hiding this comment.
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
CommandLineUtils/src/Hosting.CommandLine/HostBuilderExtensions.cs
Lines 60 to 83 in df0a511
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); | |
}); |
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; |
There was a problem hiding this comment.
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 :-/
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to duplicate
CommandLineUtils/src/Hosting.CommandLine/HostBuilderExtensions.cs
Lines 85 to 93 in df0a511
using var host = hostBuilder.Build(); | |
await host.RunAsync(cancellationToken); | |
if (exceptionHandler.StoredException != null) | |
{ | |
ExceptionDispatchInfo.Capture(exceptionHandler.StoredException).Throw(); | |
} | |
return state.ExitCode; |
Task<int> RunCommandLineApplicationAsync
method could be replaced with two chained calls to new API you are proposing in this PR.
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. |
@hellfirehd I'll give this a shot and pick up where you left off. |
@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. |
No description provided.