Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket

App configuration

Configure the Configured Commerce Mobile SDK.

App configuration service

There is a Configuration.json file in the root of the CommerceMobileApp.Core directory.

The IAppConfigurationService interface has a member definition for each value included in the Configuration.json file. IAppConfigurationService is implemented in AppConfigurationService.cs in the CommerceMobileApp.Core/Services directory.

AppConfigurationService.cs contains two classes:

  1. Configuration - an internal class used as a model to deserialize the Configuration.json object
  2. AppConfigurationService - implementation of the interface

Add to configuration service

You can add to this configuration in a few simple steps.

  1. Add your property to the Configuration.json file.
    Below, MyNewConfigurationOption is an example assigned a default string value.

    {  
    ...  
    // Already existing config values here  
     ...  
    "MyNewConfigurationOption" : "defaultConfigurationOptionValue"  
    }  
    
  2. Add your property to Configuration & IAppConfigurationService, the internal class that helps to deserialize the JSON object. Be sure to include the accessors and mutators.

    internal class Configuration
    {
    ...
     // Already existing members here
     ...
    
     public string MyNewConfigurationOption { get; set; }
    }
    public interface IAppConfigurationService
    {
    ...
    // Already existing members here
     ...
      string MyNewConfigurationOption { get; }  
    }
    
  3. Add your property to AppConfigurationService and assign it the value retrieved from the JSON object.

     public class AppConfigurationService : ServiceBase, IAppConfigurationService
        {
            ...
            
            public string MyNewConfigurationOption { get; }
            
            ...
            
            public AppConfigurationService(ICommerceAPIServiceProvider commerceAPIServiceProvider)
            : base(commerceAPIServiceProvider)
            {
                ... 
                
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    string json = streamReader.ReadToEnd();
                    var configuration = JsonConvert.DeserializeObject<Configuration>(json);
                    
                    ...
                    
                    this.MyNewConfigurationOption = configuration.MyNewConfigurationOption;
                }
            }
        }
    
  4. Access your new configuration property in the code.

    string myConfigOption = coreServiceProvider.GetAppConfigurationService().MyNewConfigurationOption;
    

To access your new property, you will need to have a reference to the CoreServiceProvider and then get the App Configuration Service. From that, you have access to your property. The above snippet assumes that you already have injected the Core Service Provider into your class and have also assigned it to a member named coreServiceProvider.