ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
I’ve been chomping away at my custom resource provider/manager and I have most of this working nicely with the ability to dynamically update resource content which was the original goal of this whole process.
But even as all of this is coming together I still feel a bit lost on the high level picture of the relationships between the ResourceProvider, ResourceManager and ResourceSets.
It looks to me that there’s one ResourceProvider per page, which in turn gets one ResourceSet at a time for each locale that is accessed. Locale information is pulled into ResourceSets one at a time it looks like as needed so as to minimize overhead until needed. The sets are cached automatically by the provider (or ResourceManager if one is used) so the resources load once and then stay cached.
All fine and good. ASP.NET allows overriding of the ResourceProvider via web.config and a custom implementation.
What I can’t figure out is how this actually happens and what is parceling out the ResourceManagers and Providers. For example, ASP.NET has a set of global resources which can be accessed with Resources.Resources. If you do this and look at the ResourceManager you’ll find that it’s the standard .NET resource manager not my custom resource manager.
It looks like there’s also no way to get a ‘global’ or ‘currently active’ reference to a ResourceProvider or ResourceManager. So if I’m in custom control how can I get a reference to the active ResourceProvider/Manager so I can do custom localization for example. Right now the control would have to know about a specific instance of the provider/manager.
I suppose I can use Page.GetLocalResourceObject(), PageGetGlobalResourceObject() for this? Is that the idea? These methods will go down to the active provider and do their thing properly. The page (or TemplateControl really) has its own ResourceProvider:
protected object GetLocalResourceObject(string resourceKey)
{
if (this._resourceProvider == null)
{
this._resourceProvider = ResourceExpressionBuilder.GetLocalResourceProvider(this);
}
return ResourceExpressionBuilder.GetResourceObject(this._resourceProvider, resourceKey, null);
}
But it’s not publicly accessible…
This makes it tough for example to ask for a ResourceWriter and write resources out to the resource store unless you hardcode to a specific provider…
Has anybody found some useful documentation that talks about the overall structure of the ResourceProvider model or more simply how to get access to the active ResourceProvider object?
Other Posts you might also like
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Getting the Client IP Address in ASP.NET Core
- Resolving Paths To Server Relative Paths in .NET Code
- Getting the ASP.NET Core Server Hosting Urls at Startup and in Requests
The Voices of Reason
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
function StartLoading() { var Ctl = $('lblProgressText'); Ctl.innerHTML = '<%= this.GetGlobalResourceObject("Resources","LoadingText") %>'; }
It's not real pretty, but that works. Alternately you can also generate a Resource section right into the JavaScript with static strings and then use those static 'variables' in the code.
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
function StartLoading()
{
var Ctl = $('lblProgressText');
ctl.innerHTML = '<asp:Localize ID="Localize1" runat="server" meta:resourcekey="Localize1Resource1"></asp:Localize>';
}
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
But, what if the javascript is embedded in a JS file. I think this both methods would not work.
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
And same time, not all the JS codes can be embedded in the .aspx page and it is not handy too. One way I can think of is embed constant variables in the .aspx page that can get the data from the way you have mentioned here and use the constant variables in JS functions while displaying any text.
I think, may be ATLAS kind of frameworks may properly address this issue.
What do you think ?
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
I've taken to unloading the AppDomain to refresh - by touching web.config. That seems to work but it's a pretty drastic step. OTOH, this is a develop time operation in most cases so it's not that big of a deal.
You can see a sample of the resource manager and interface here:
http://www.west-wind.com/presentations/wwhoverpanel/sample/ResourceProvider/CustomerList.aspx
# re: ResoureProvider, ResourceManagers Relationships in ASP.NET 2.0
Is there anything out there ?
-
Vadi