我正在尝试将此方法转换ExportTo3rdParty()
为使用 AsyncController:
public JsonResult SaveSalesInvoice(SalesInvoice invoice)
{
SaveInvoiceToDatabase(invoice); // this is very quick
ExportTo3rdParty(invoice); // this is very slow and should be async
}
但是 ExportTo3rdParty() 方法在多个地方使用了 HttpContext.Current(太多以至于无法更改 - 原始编码器没有使用足够的依赖注入)。例如,它调用 GetDefaultCurrency()。当通过 AsyncController 调用 ExportTo3rdParty() 时,这仍然有效吗?
public Currency GetDefaultCurrency()
{
Currency currency;
string key = string.Format("DefaultCurrency_{0}",
HttpContext.Current.User.Identity.Name);
currency = HttpRuntime.Cache.Get(key) as Currency;
if (currency == null)
{
currency = LookupDefaultCurrency();
HttpRuntime.Cache[key] = currency;
}
}
我知道如果我使用 Thread.Start 我无法访问 HttpContext.Current。但是 AsyncController 呢?