Is RequestLocalizationMiddleware thread-safe? #49012
-
My use case is the next: a RESTful endpoint will be exposed to millions of users. This endpoint will return a string (stored in a resx), but in the language requested by the client with the HTTP header For that, I've added the next line of code to app.UseRequestLocalization(); With this, you add the middleware
Given those descriptions and the amount of incoming HTTP requests to the endpoint, I have the next doubts:
The documentation doesn't clarify this: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization/select-language-culture?view=aspnetcore-8.0 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Short answer yes, it’s thread safe. If it wasn’t it would be unusable. Current culture is an async local. It’s a local that implicitly flows throughout async calls (conceptually like a thread local but for async code) |
Beta Was this translation helpful? Give feedback.
Short answer yes, it’s thread safe. If it wasn’t it would be unusable.
Current culture is an async local. It’s a local that implicitly flows throughout async calls (conceptually like a thread local but for async code)