RickStrahl / Westwind.Globalization

Database driven resource localization for .NET applications
544 stars 135 forks source link

Question about Westwind.Globalization extensibility #22

Closed apuchkov closed 9 years ago

apuchkov commented 9 years ago

We plan to use Westwind.Globalization not only for localization, but also as a tool for customization of labels / headlines via web UI by administrator, kind of mini CMS.

The catch is that customizations can be different for different users, more specifically for user companies. Think of overriding a logo, company name or welcome text for different companies. So when user logs in he sees a welcome text based on a company he belongs to.

Ideally we would use some extensibility points in Westwind.Globalization to have this functionality, but I don't think there are any. Looks like we will need to fork the project, add CompanyId column to the database table and update UI to allow overriding of resources per company.

Is there a way to have this kind of functionality without forking? Any suggestions what the best approach would be?

RickStrahl commented 9 years ago

Great question, but unfortunately I don't think there's a good solution to this issue.

The reason is that these tools use the .NET globalization infrastructure which uses ResourceSets/ResourceProviders, which internally cache their data. This means the each ResourceSet per Locale loads once and then stays loaded and cached for the duration of AppDomain lifetime. It's not really meant for dynamic change or dynamic selection - this is effectively static data.

You can potentially affect how the resource sets load by overriding behavior in the load process and that's possible today by using ResourceSetValueProviders as described here: ResourceSet ValueProviders

ValueConverters are called just before resources are loaded into the ResourceSet (and before they get cached). With these value converters you can override the value behavior but again this is global to the application (AppDomain) as required by the .NET Resource architecture.

Once you start adding fields to the database though, you have to fork though because otherwise there's no way to get at the value. One idea might be to modify this library to have one 'tag' field that can be used for custom identifier data.

apuchkov commented 9 years ago

Thanks for a very detailed reply.