views:

147

answers:

5

I am currently working on a project that requires Static Text to be configurable(including labels, messages, and validation errors). I was wondering what the best approach would be. The app is being written using ASP.NET MVC and C# 3.5. I need all this static configurable text to be fed to the MVC project from a different project. I thought of using Global Resources, or using an XML file that would be loaded on application start. By the way, this is not about localization, also static text won't be configurable by the end-user.

A: 

I would store it in the AppSettings section in the Web.Config file.

James
This could become messy really quickly depending on the amount of text and if it would contain special characters (web.config is XML)
borisCallens
Personally I wouldn't put this data in web.config, as any change to the text would mean an app restart, which is unneccessary here.
JonoW
Bear in mind my answer came before John actually stated the information could change at any time.
James
A: 

You could use AppSettings and web.config as James answered. you could also store it in a database, with key value pair structure.

But you also need to get it from the configuration project to the ASP.Net MVC project. I would do it like this:

  • Create a service interface on the configuration project
  • use Enterprise Library Caching in the ASP.Net MVC project
  • Check if the value is cached
  • If not get it from the configuration and store it in the cache
Shiraz Bhaiji
A: 

Localization is actually a decent way to handle this--it is solving the same problem, you'd just need to provide a single language file. Downside is that localization bits are not necessarily easily end-user editable. Which drives me to the fact that the real question to answer here is "how user editable is this information going to be?" If the answer is "frequently and easily" then you might want to make some sort of UI Snippets table in your database and handle it accordingly. Another decent option would be to use a custom configuration section and read/write to it using the configuration API. Also leaves open hand-editing XML files if need be.

Wyatt Barnett
This static text won't be configurable by the end-user.
John
Interesting. Then why separate it out? If you are not doing il8tion and people are not editing it, it makes little sense . . .
Wyatt Barnett
A: 

I would use a XML file with a single load at the application startup

Gregoire
+1  A: 

I would probably make a separate project that contained a series of Resx files, these are pretty easy to work with and give you localization for free. This is where I would start and if you need to edit them on the fly through some admin tool then you could use something like Rick Strahl's data driven provider. This is probably a better approach then trying to come up with your own DB driven design.

I do agree that you probably need to clarify a bit of how and when the text will be editable.

Definitely stay away from the web.config and appsettings unless we are only talking about 1 or 2 lines of text. In general this is not a good idea for many of the reasons others have stated about app restarts and just general config bloat.

Greg Roberts