views:

42

answers:

1

I am building a Silverlight application that takes a single InitParam that will be used throughout an application (at least in a number of services). We are looking at building the app using Prism and what I would like to know is - how do we instantiate a service that takes this parameter and makes it globally available?

+1  A: 

Are you asking how to read the InitParams or what you should do with it once you've read it? To read it, you access it in the StartupEventArgs in the Application.Startup event.

private void Application_Startup(object sender, StartupEventArgs e) {
    string blah;
    if (e.InitParams.TryGetValue("ID", out blah)) {
        ...
    }
}

Once you get it out, I suppose you could add it to your container as a named string. Or you could just stick the StartupEventArgs in the container and access it as needed.

Josh Einstein
Apologies for being vague. I know how to read the InitParams but I was just wondering the best approach to propagating the values around the system that isn't tightly coupling things. The named strings approach seems like it might be the best.
kouPhax
OK I registered an instance of a config obejct with the conatiner. A lot simpler than I thought it was going to be. Thanks
kouPhax
Something else to consider is Application services in Silverlight 3 and above. Check out http://wildermuth.com/2009/08/24/The_Application_Class_and_Application_Services_in_Silverlight_3 for more information. Pay particular attention to IApplicationService and <Application.ApplicationLifetimeObjects>
Jordan