You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Moving CancelOnProcessTermination out of middleware, better cancellation support (#2044)
* InvocationPipeline can be static
* don't await a task-returning method when we can just return the task (less boilerplate and allocs)
* don't register services when creating BindingContext in InvocationContext.BindingContext getter, as BindingContext ctor already does that
* don't use BindingContext when there is no need to (it's expensive)
* don't register CancellationToken inside ServiceProvider, pass the token in explicit way to Handler
* move CancelOnProcessTermination out of middleware
* RemoteExecutor does not support getting application arguments, Process.WaitForExitAsync is available only on .NET 7+
* extend Middleware with CancellationToken so it can be passed to Hosting
Co-authored-by: Kevin B <[email protected]>
Copy file name to clipboardExpand all lines: src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_Hosting_api_is_not_changed.approved.txt
Copy file name to clipboardExpand all lines: src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_NamingConventionBinder_api_is_not_changed.approved.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -99,7 +99,7 @@
99
99
public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.Argument argument)
100
100
public System.Void BindParameter(System.Reflection.ParameterInfo param, System.CommandLine.Option option)
101
101
public System.Int32 Invoke(System.CommandLine.Invocation.InvocationContext context)
102
-
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.CommandLine.Invocation.InvocationContext context)
102
+
public System.Threading.Tasks.Task<System.Int32> InvokeAsync(System.CommandLine.Invocation.InvocationContext context, System.Threading.CancellationToken cancellationToken = null)
103
103
public class ModelDescriptor
104
104
public static ModelDescriptor FromType<T>()
105
105
public static ModelDescriptor FromType(System.Type type)
Copy file name to clipboardExpand all lines: src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt
+15-17Lines changed: 15 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -116,27 +116,27 @@ System.CommandLine
116
116
public static class Handler
117
117
public static System.Void SetHandler(this Command command, System.Action<System.CommandLine.Invocation.InvocationContext> handle)
118
118
public static System.Void SetHandler(this Command command, System.Action handle)
119
-
public static System.Void SetHandler(this Command command, System.Func<System.Threading.Tasks.Task> handle)
120
-
public static System.Void SetHandler(this Command command, System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.Tasks.Task> handle)
119
+
public static System.Void SetHandler(this Command command, System.Func<System.Threading.CancellationToken,System.Threading.Tasks.Task> handle)
120
+
public static System.Void SetHandler(this Command command, System.Func<System.CommandLine.Invocation.InvocationContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle)
121
121
public static System.Void SetHandler<T>(this Command command, Action<T> handle, IValueDescriptor<T> symbol)
122
-
public static System.Void SetHandler<T>(this Command command, Func<T,System.Threading.Tasks.Task> handle, IValueDescriptor<T> symbol)
122
+
public static System.Void SetHandler<T>(this Command command, Func<T,System.Threading.CancellationToken,System.Threading.Tasks.Task> handle, IValueDescriptor<T> symbol)
Copy file name to clipboardExpand all lines: src/System.CommandLine.Generator/CommandHandlerSourceGenerator.cs
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -115,10 +115,10 @@ private class GeneratedHandler_{handlerCount} : {ICommandHandlerType}
115
115
}
116
116
117
117
builder.Append($@"
118
-
public int Invoke(global::System.CommandLine.Invocation.InvocationContext context) => InvokeAsync(context).GetAwaiter().GetResult();");
118
+
public int Invoke(global::System.CommandLine.Invocation.InvocationContext context) => InvokeAsync(context, global::System.Threading.CancellationToken.None).GetAwaiter().GetResult();");
119
119
120
120
builder.Append($@"
121
-
public async global::System.Threading.Tasks.Task<int> InvokeAsync(global::System.CommandLine.Invocation.InvocationContext context)
121
+
public async global::System.Threading.Tasks.Task<int> InvokeAsync(global::System.CommandLine.Invocation.InvocationContext context, global::System.Threading.CancellationToken cancellationToken)
0 commit comments