ASP.NET Resource file question...

ASP.NET Resource file question...

Old forum URL: forums.lhotka.net/forums/t/2278.aspx


JCannelos posted on Monday, February 05, 2007

Guys,

I am developing a ConsultingTracker web app similar to Rocky's ProjectTracker. In the web app, I have a global resources file to handle strings such as UserCreatedMsg and so on. However in my business objects, when server side validation fails, it seems that I need another Resources file there for messages like NoDuplicatesAllowed, et. These are custom Csla.Validation handlers that need to have certain Resource file messages upon failure.

My question is - do I need to have two Resource files (one on web, one in business object library) or is there a way to consolidate. I noticed that my Resources file in the business object library was marked "internal" - any thoughts on making this "public"?

Thanx!

J'son

 

SonOfPirate replied on Tuesday, February 06, 2007

Unfortunately, this is a common problem.  I have a couple of multi-tiered apps in progress where I've had to duplicate string data in two to three different resource files because there is no easy way to share this data from base library to client app.  Here are a few ways to get around this, it's up to you if any are appealing:

1. Microsoft suggests changing the scope of each property in the resource file to public so that it will be available to client apps.  Unfortunately, the next time you open the resource file in the designer, it will reset them all back to internal and you'll be back to square one.

2. Create a proxy class that exposes the same properties as in your resource file but delegates to the internal resource file.  For example:

    public namespace Resources
    {
        public class Strings
        {
            public string HelloWorld
            {
                get
                {
                    return InternalResources.Strings.HelloWorld;
                }
            }
        }
    }

Of course, you'll have to be diligent to make sure that this class remains in-sync with the internal resource file.

3. I believe there is a way to accomplish this using external resource files that can be shared between assemblies, but I've never done this so I'm not sure what is required.

 

If there are other suggestions, I'd be anxious to hear them.

HTH

 

JCannelos replied on Tuesday, February 13, 2007

Thanx, SonOfPirate... thats what I figured. :(

J'son

Copyright (c) Marimer LLC