最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - Consideration about using AsyncLocal<CancellationToken > to pass CancellationToken directly to destination

programmeradmin3浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

The 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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论