如何访问AsyncLocal

时间:2016-04-07 04:40:31

标签: c# asp.net-core

经典.net CallContext已替换为AsyncLocal中的.NET 4.6 ...并且可在ASP.NET Core中使用。我注意到最新版本的SimpleInjector is using it

但是,我无法在我的dnx451 ASP.NET Core项目中使用它。

我可以做以下两个声明:

using System.Threading;
using System.Threading.Tasks;
...
static ThreadLocal<string> foo = new ThreadLocal<string>();
static AsyncLocal<string> tenant = new AsyncLocal<string>();

第一个很好,但第二个没有正确定义,如此消息所示:

AspAsyncLocal.DNX 4.5.1 - Not Available
AspAsyncLocal.DNX Core 5.0 - Available

我错过了什么?我的project.json有以下依赖项:

"dependencies": {
  "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
  "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
  "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
  "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
},

"frameworks": {
  "dnx451": {
    "dependencies": {
      "System.Threading": "4.0.11-beta-23516"
    }
  },
  "dnxcore50": { }
},

1 个答案:

答案 0 :(得分:1)

尝试使用$test_num代替dnx46