4

I have a central library (DLL) called Core that is used by many projects (Some web apps, some win forms, some other class libraries).

Some resources are stored in the Core library.

When I need to use a resource file in the Core library, I need to know what the culture info is. Because it is sometimes used in a win form app, sometimes in a web app, I can't really use the culture from HttpContext or from the CurrentThread.

I imagine that this a common problem, so I am wondering :

What's a good strategy to pass the culture information around between DAL dlls and UI projects?

Hugo Migneron
  • 4,867
  • 1
  • 32
  • 52

2 Answers2

2

You can always get the culture from the CurrentThread. It's supported both in WinForms and Web Applications. Even better: you'll probably won't need to bother about this at all, as the resource manager in .NET will handle this based on the current culture.

Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120
  • And the current culture in a web app will be set with the culture of the user (and not the culture of the server running the web app)? – Hugo Migneron May 16 '11 at 16:01
  • 1
    @Hugo it is up to the web application to set the current thread's CurrentCulture/CurrentUICulture on each request. They'll find out real quick if they aren't doing it right. – Joshua May 16 '11 at 16:04
  • Thanks, setting the culture info from the UI thread and getting it down that way makes a lot of sense. – Hugo Migneron May 16 '11 at 16:10
1

You can set the ui culture for a thread.

Then you are already fixed in case of WinForms.

In aspnet, you will need to set current ui culture for the thread. You can hook this procedure in a base controller's OnActionExecuted for this purpose (MVC) or use the PreInit event (webforms). This also can be done in an HttpModule.

George Polevoy
  • 7,450
  • 3
  • 36
  • 61