private static IServiceCollection RegisterConfigurations(IServiceCollection services) { try { var dirInfo = new DirectoryInfo(Assembly.GetExecutingAssembly().Location); var rsgConfigSrc = Path.Combine(dirInfo.Parent.FullName, LoadRsgConfiguration.ExternalConfigurationName); var isRsgConfigInternal = false; var useInternalRsgConfig = string.IsNullOrEmpty(rsgConfigSrc) || !IOUtility.DoesFileExist(rsgConfigSrc); if (useInternalRsgConfig) { rsgConfigSrc = LoadStringConfiguration.InternalConfigurationName; isRsgConfigInternal = true; } var rsgConfiguration = new LoadRsgConfiguration().LoadJson(rsgConfigSrc, isRsgConfigInternal); services .AddSingleton(rsgConfiguration); var stringConfigSrc = rsgConfiguration.StringConfigurationSource; var isStringConfigInternal = false; var useInternalStringConfig = string.IsNullOrEmpty(rsgConfiguration.StringConfigurationSource) || !IOUtility.DoesFileExist(stringConfigSrc); var stringPathToSerialize = Path.Combine(dirInfo.Parent.FullName, LoadStringConfiguration.ExternalConfigurationName); if (useInternalStringConfig) { stringConfigSrc = LoadStringConfiguration.InternalConfigurationName; isStringConfigInternal = true; } var stringConfiguration = new LoadStringConfiguration().LoadJson(stringConfigSrc, isStringConfigInternal); services .AddSingleton <ICharacterSetProvider>(stringConfiguration); var dictionaryConfigSrc = rsgConfiguration.DictionaryConfigurationSource; var isDictionaryConfigInternal = false; var useInternalDictionaryConfig = string.IsNullOrEmpty(rsgConfiguration.DictionaryConfigurationSource) || !IOUtility.DoesFileExist(stringConfigSrc); var dictionaryPathToSerialize = Path.Combine(dirInfo.Parent.FullName, LoadDictionaryConfiguration.ExternalConfigurationName); if (useInternalDictionaryConfig) { dictionaryConfigSrc = LoadDictionaryConfiguration.InternalConfigurationName; isDictionaryConfigInternal = true; } var dictionaryConfiguration = new LoadDictionaryConfiguration().LoadJson(dictionaryConfigSrc, isDictionaryConfigInternal); services .AddSingleton <IDictionaryProvider>(dictionaryConfiguration); if (useInternalStringConfig) { SerializationUtility.SerializeJson(stringConfiguration, stringPathToSerialize); } if (useInternalDictionaryConfig) { SerializationUtility.SerializeJson(dictionaryConfiguration, dictionaryPathToSerialize); } if (useInternalRsgConfig) { // Since we are using the internal rsg configuration file, set the new paths to string and dictionary configurations. rsgConfiguration.StringConfigurationSource = stringPathToSerialize; rsgConfiguration.DictionaryConfigurationSource = dictionaryPathToSerialize; SerializationUtility.SerializeJson(rsgConfiguration, Path.Combine(dirInfo.Parent.FullName, LoadRsgConfiguration.ExternalConfigurationName)); } } catch (Exception e) { LogUtility.Write("Rsg Configuration", $"Unable to load internal/external rsg configuration(s).", e); throw e; } return(services); }