Autofac and Web API scopes

2019-06-24 01:55发布

问题:

Earlier i saw this:

.InstancePerApiRequest();

Now i only got this:

.InstancePerHttpRequest();

Did autofac removed the API-scope? I have the reference Autofac.Integration.WebApi but this extension is not available. What is the difference between InstancePerHttpRequest and InstancePerApiRequest?

回答1:

InstancePerApiRequest is part of the Web API integration, and InstancePerHttpRequest is part of the MVC integration. These both actually apply the same tag to the lifetime scope. That was done because you might have services that are dependencies of both Web API and MVC controllers.