Catel help manual-catel. Core :( 3) configuration instructions

Source: Internet
Author: User

 

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.