How do I dispose of resources after an ASP.NET Web API request completes?

前端 未结 1 1688
执笔经年
执笔经年 2021-01-03 11:10

I am attempting to expose an IQueryable<> over ASP.NET Web API and I find that I need to keep the data source open until the request completes, so that th

相关标签:
1条回答
  • 2021-01-03 11:41

    You can use the extension called RegisterForDispose on the HttpRequestMessage to register any resources that you would like to dispose off when a request is done.

    BTW, you might want to look at the following link to regarding IQueryable support in next release of Web API. http://aspnetwebstack.codeplex.com/discussions/359229

    [Edited] Doing things in Dispose() method of the Controller would also be a solution. In Web API ApiController based controllers are always per-instance (one controller instance per one request)

    0 讨论(0)
提交回复
热议问题