Catel makes it easier for you to configure all platforms.
The following table explains the technologies used by each platform to obtain and store configuration values.
Platform |
Technology |
. Net |
Configurationmanager. deleettings |
Sliverlight |
Isolatedstoragesettings. applicationsettings |
Winrt |
Applicationdata. Current. localsettings |
PCL |
Not Supported |
1. Get the value from configuration
Use the following code to obtain the value from the Configuration:
var configurationService = new ConfigurationService();var mySetting = configurationService.GetValue<int>("mySetting", 42);
Note:
It's best to retrieve the service from the dependency resolver or let it be injected into the classes using it
2. Set the value to the configuration item.
Use the following code to store values in the Configuration:
var configurationService = new ConfigurationService();configurationService.SetValue("mySetting", 42);
Note:
It's best to retrieve the service from the dependency resolver or let it be injected into the classes using it
3. Storage of custom values
Configurationservice is used for extension, although its default is. net local storage system, it is easy to create a custom service, the following is an example of creating a Custom Service to store or read the database.
public class DbConfigurationService : ConfigurationService{ protected override bool ValueExists(string key) { using (var context = new ConfigurationContext()) { return (from config in context.Configurations where config.Key == key select config).Any(); } } protected override string GetValueFromStore(string key) { using (var context = new ConfigurationContext()) { return (from config in context.Configurations where config.Key == key select config.Value).First(); } } protected override void SetValueToStore(string key, string value) { using (var context = new ConfigurationContext()) { var configuration (from config in context.Configurations where config.Key == key select config).FirstOrDefault(); if (configuration == null) { configuration = context.CreateObject<Configuration>(); configuration.Key = key; } configuration.Value = value; context.SaveChanges(); } }}
Note:
Do not forget to register a custom configurationservice in servicelocator.
Catel help manual-catel. Core :( 3) configuration instructions