Reputation: 1503
I'm developing a PCL that will be used by Windows Store and WP8 apps. This library requires some configuration e.g. remote service url. I wanted to put those into the app.config and retrieve them using ConfigurationManager, but the System.Configuration doesn't seem to be available in PCL.
Upvotes: 3
Views: 2714
Reputation: 108790
I'd create a configuration class. In the simplest case1 it could look like:
public class MyLibraryConfig
{
public string RemoteServiceUrl{get;set;}
}
Then pass an instance of this class to the library via standard dependency injection techniques. For example pass it into the constructor and store it in a field. Then it's the application's responsibility to read the configuration from a file, the ConfigurationManager
, etc.
IMO this is much better design and I'd use it over querying the configuration manager even in libraries where I could access the ConfigurationManager
. Else you force the application to use a single configuration and to use a specific configuration mechanism.
1 you can also use an interface or an immutable class. That's slightly more complex, but IMO better design.
Upvotes: 2