WebApi, Autofac, System.Web.Http.Filters.ActionFilterAttribute Instance Per Request

五迷三道 提交于 2019-12-04 03:16:14

This is a known issue and a design problem in Web API. When filter instances are first created in Web API they are cached, so Autofac has to resolve the property injection using the root lifetime scope, not the request lifetime scope. There is no opportunity on a per-request basis for Autofac to do any property injection - the filters are effectively singletons within Web API and there's no hook to change that.

Thereafter, if you need per-request services in your filter, you have to use that GetDependencyScope() trick.

See these issues on Autofac for more details:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!