Uploaded image for project: 'Constretto Core'
  1. Constretto Core
  2. CC-14

Introduce ConstrettoConfigurationFactory

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.1
    • Component/s: None
    • Labels:
      None

      Description

      The API provided by ConstrettoBuilder creates very verbose client code when the same ini or properties file is accessed to define constants across various class files.

      For example a repetition of the following happens

      import static org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX;

      public static final String CONSTANT_A = new ConstrettoBuilder()
      .createIniFileConfigurationStore()
      .addResource(new DefaultResourceLoader().getResource(CLASSPATH_URL_PREFIX + "file.ini"))
      .done()
      .getConfiguration()
      .evaluateToString("CONSTANT_A");

      public static final String CONSTANT_B = new ConstrettoBuilder()
      .createIniFileConfigurationStore()
      .addResource(new DefaultResourceLoader().getResource(CLASSPATH_URL_PREFIX + "file.ini"))
      .done()
      .getConfiguration()
      .evaluateToString("CONSTANT_B");
      The attached factory provides convenience methods to simplify the above code into the following

      import static org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX;
      import static no.finntech.commons.constretto.ConstrettoConfigurationFactory.iniFile;

      public static final String CONSTANT_A = iniFile(CLASSPATH_URL_PREFIX + "file.ini").evaluateToString("CONSTANT_A");

      public static final String CONSTANT_B = iniFile(CLASSPATH_URL_PREFIX + "file.ini").evaluateToString("CONSTANT_B");
      It also caches the ConstrettoConfigurations to improve application performance.

        Attachments

          Activity

            People

            • Assignee:
              kaare.nilsen@gmail.com Kaare Nilsen
              Reporter:
              kaare.nilsen@gmail.com Kaare Nilsen
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: