What is the correct simple request style for a simple injector for use in a ServiceStack API application?

I have a ServiceStack API application that uses Simple Injector as an IoC container. I need some components to have a lifestyle for every web request.

I looked at the Simple Injector documentation here and found that it doesn’t have one, but two lifestyles matching “for web request”,

  • In web request
  • Web API Request

This drove me crazy because I always thought that all ASP.NET applications use the same basic pipeline and that IoC containers are implemented for each web request by connecting the HTTP module. Why will this be different for Web API applications?

Can someone shed the light that is most suitable for the ServiceStack API application?

+4
source share
1 answer

Per Web Request is actually an “HttpContext request,” and under the cover, it caches instances using a dictionary HttpContext.Current.Items. This model, however, begins to break down quickly when you use the web API, which is caused by the asynchronous web API model and the fact that web API applications can work in (which means: no there HttpContext.Currentat all).

Simple Injector Web API. Perry API API , .

- , API ServiceStack?

ServiceStack , WebApiRequestLifestyle ExecutionContextScopeLifestyle. HttpRequest.Current ServiceStack, WebRequestLifestyle.

+5

Source: https://habr.com/ru/post/1530230/


All Articles