简体   繁体   中英

Strategy for sharing resources between projects

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM