Global variables

Topics: CAB & Smart Client Software Factory
Nov 29, 2007 at 11:00 PM
I wanted to know where should we define global variables in SCSF application? Is there an alternative for global variables. In my application I have a lot of setting that each module will be sharing.
Nov 30, 2007 at 7:12 AM

ila wrote:
I wanted to know where should we define global variables in SCSF application? Is there an alternative for global variables. In my application I have a lot of setting that each module will be sharing.


Global variables are bad :-)

But this is an ideal candidate for a Service. We have a similar situation where I work, and we created an AppSettingsService that is added to the Services collection in the RootWorkItem when the Shell starts up. When the app loads, it queries a remote facade and fetches all of the values necessary to hydrate the service (thus the loading only happens once, at startup). From there, we can fetch the AppSettingsService in any WorkItem or Presenter or View any time we need via dependency injection, and make use of the values.

As a Service, we can then mock it for testing, and since we're coding to an IAppSettingsService interface, we could replace the implementation if ever necessary.

Nov 30, 2007 at 5:29 PM
Thanks for the reply, can you point me to a code example which I can follow to understand this concept better.