0

I'm developing SVC services and a class library in .Net 4.5.

First of all, all the services are receiving some headers to check the user.

WebOperationContext woCtx
string token = woCtx.IncomingRequest.Headers["token"];
// check the token via WS and return a response containing some info

After this check I get user's info like the Culture. The culture is used in many methods in the library. Now I have two solutions:

  1. I can pass the culture as a parameter in every method.

  2. Set Thread.CurrentThread.CurrentUICulture and use it

I'd know if class library is thread safe or different requests done by different users will be overwritten. Moreove I don't like to use Threads in a class library.

I have already excluded to use a static property of a static class for the same reason.

Emanuele
  • 648
  • 12
  • 33
  • How are you handling the user's info now? You mention you are getting the user's info including the culture so I am assuming there are other things like user name, etc. Do the methods use this info too? – pstrjds Apr 10 '18 at 08:46
  • I need just the culture – Emanuele Apr 10 '18 at 09:01
  • Passing culture as a method argument makes for very awkward programming. Maybe that is a valid approach in your case, it is however pretty uncommon. A thread works on a service request, the requester doesn't switch their native language on the fly. Do note that it is a property of a thread (you meant to use Thread.CurrentCulture) and different threads can handle different service requests, each having their own culture. Pretty important to target .NET 4.6, it ensures that any other thread you start while handling the service request uses the same culture. – Hans Passant Apr 10 '18 at 09:35
  • Can i be sure: 1 ws call = user = his culture? – Emanuele Apr 10 '18 at 09:48

0 Answers0