Configure White Label Sample App Global Settings
info
This is our least favourite technique, as it includes each Build Configuration in the compiled apps code base. However when you have twenty apps, with a lot of configuration items, it can make it easier to ensure that every app has a complete configuration, by using an initialised flag on each configuration, and it can be more refactorable.
To use this you would
- Create multiple constants definitions for each configuration
- Create a GlobalSettings.cs static class, or a Singleton, injectable with Dependency Injection
- Use an Init() method on App Startup to configure the settings
TheAppsPajamas.White/Constants/ApiAccountSettings.cs
using System; namespace TheAppsPajamas.White.Constants { public static class ApiAccountSettings { public static string Username { get; set; } public static string Password { get; set; } public static void Init() { #if BEAR InitBear(); #elif BLUE InitBlue(); #elif FLUFFY InitFluffy(); #elif TEST InitTest(); #endif } private static void InitBear() { Username = Bear.ConfigPassword; Password = Bear.ConfigPassword; } private static void InitBlue() { Username = Blue.ConfigPassword; Password = Blue.ConfigPassword; } private static void InitFluffy() { Username = Fluffy.ConfigPassword; Password = Fluffy.ConfigPassword; } private static void InitTest() { Username = Test.ConfigPassword; Password = Test.ConfigPassword; } private static class Bear { public const string ConfigUsername = "bear"; public const string ConfigPassword = "NEb46BEq944Z9WKgJxvpCZa8Ckh578kR8WQ"; } private static class Blue { public const string ConfigUsername = "blue"; public const string ConfigPassword = "ReNFRTEUWFYmhe9cfvmGkGwwp3V4trRDF9N"; } private static class Fluffy { public const string ConfigUsername = "fluffy"; public const string ConfigPassword = "4nNeqf3jFaVMJE9HpsTsd5mkAPdWtk3aPQc"; } private static class Test { public const string ConfigUsername = "test"; public const string ConfigPassword = "test"; } } }