0

I have a few configuration flags that I want to be able to set on/off via an http call (similar to a REST call).

Normally you store configuration settings in the web.config, or you pull things our from a file into a class, and this configuration class that you use throughout your application code is used as if it a singleton class or constants.

There is one property that I want to be able to modify at runtime, and this is a global variable. Any modifications will be done by a single user or thread, and will occurr very rarely.

How should I design this and where should I store this?

My application code calls the Twitter API, but I want to be able to switch on/off if I should call the twitter API (it could be down), where should I store this on/off property knowing that I want to be able to update this field?

if(SomeClass.TwitterApiEnabled) 
{
   // call twitter api
}

I could toggle the TwitterApiEnabled property on/off using:

http://www.example.com/api/twitter/enable=no&auth_token=123
loyalflow
  • 14,275
  • 27
  • 107
  • 168

2 Answers2

1

I think that the only sensible way to store this would be storing this to a database / file in some manner as storing this in memory would mean on re-boot that the setting is lost.

Why not save a file call TwitterDisabled and when this is present twitter is disabled. Shouldn't really affect performance of you cache this per user session.

TheKingDave
  • 926
  • 1
  • 8
  • 16
0

1) Application variable -- these are global variables stored in a key/value pair Application["TwitterIsUp"] = isTwitterUp;

you'll need to cast it to get it out...

return (bool) Application["TwitterIsUp"];

2) Static field

dbugger
  • 15,868
  • 9
  • 31
  • 33
  • The application variables are nothing more than a static Dictionary. – Aristos Jan 21 '13 at 16:50
  • That are updatable and readable globally. Sometimes, that's all you need. – dbugger Jan 21 '13 at 16:52
  • As any static variable. Read about: http://stackoverflow.com/questions/10960695/using-static-variables-instead-of-application-state-in-asp-net/10964038#10964038 Microsoft says: ASP.NET includes application state primarily for compatibility with classic ASP – Aristos Jan 21 '13 at 16:52