将 Autofac 用于 webform 和 web api 相同的应用程序

Use Autofac for webform and web api same app

我在同一个项目中使用 web api 和 webform 在webform中,我们可以使用page_unload来配置scope。 请求完成后,如何在 Web api 中释放作用域。

您关于 Web 表单使用的假设存在问题 - 您没有在 Page_Unload 上处理范围。您应该使用 the web forms integration as documented here,它会在您的管道中放置一些 HttpModule 实现,以便在正确的时间自动处理范围 (End_Request)。

您可以在同一个应用程序中使用 Web API integration as documented here,一切都会很好地协同工作。 Web API 集成将自动为您处理作用域的处理。