I found a similar post here that also discussed about this topic. It seems this solution is not recommeded because of performance issue.
Ex: passing a number to MethodA(num) then MethodB(num) and then MethodC(num). A invokes B and B invokes C.
This example is simulating my .NET API project, instead of passing cancellationToken from controller's method, we can pass it directly to the repository layer (where DB queries need to cancel operations).
Is there any other way or Microsoft updated something to deal with the wandering parameter (passing down param to nested methods) ? I don't want my methods accept unncessary params.
I found a similar post here that also discussed about this topic. It seems this solution is not recommeded because of performance issue.
Ex: passing a number to MethodA(num) then MethodB(num) and then MethodC(num). A invokes B and B invokes C.
This example is simulating my .NET API project, instead of passing cancellationToken from controller's method, we can pass it directly to the repository layer (where DB queries need to cancel operations).
Is there any other way or Microsoft updated something to deal with the wandering parameter (passing down param to nested methods) ? I don't want my methods accept unncessary params.
Share Improve this question asked Feb 17 at 8:38 tan truong thetan truong the 13 bronze badges1 Answer
Reset to default 0The normal inbuilt convention is explicit parameter passing. Can you do it your own way with AsyncLocal<T>
? Sure: if that works for you: no problem! But there is no inbuilt support for this (at any of the runtime, compiler, or analyzer levels), so it would only apply to your code. The post you already linked to discusses some of the factors that may have contributed, but either way: as a brute fact, it is what it is - at this point: the convention is set.