I'm using ASP.NET Web API 2,
I have resx files for errors, I need to return the error in the correct language (by user culture).
My solution is
1)I created BaseApiController that all the other controllers would inherit.
2)In BaseApiController I changed the Thread.CurrentThread.CurrentCulture for each request.
My question is if this is the correct way for doing it?
Thanks a lot!
There are lots of way doing this. It actually depends on your architecture. Your way is also acceptable. You will implement ResourceManager if you use your way. Let me give some other examples:
You can keep language code in request header and you don't need to change Thread.CurrentThread.CurrentCulture.
You can store errors in database with language code and you can get corresponding error with the active culture when the operation is failed.
You can store errors in cache with language code and you can get corresponding error with the active culture when the operation is failed.
As you can see, there are lots of ways. As I said it depends on your architecture.
Good luck