@@ -25,6 +25,8 @@ namespace Azure.DataApiBuilder.Config;
25
25
/// </remarks>
26
26
public class FileSystemRuntimeConfigLoader : RuntimeConfigLoader
27
27
{
28
+ // This stores either the default config name e.g. dab-config.json
29
+ // or user provided config file.
28
30
private string _baseConfigFileName ;
29
31
30
32
private readonly IFileSystem _fileSystem ;
@@ -42,13 +44,20 @@ public class FileSystemRuntimeConfigLoader : RuntimeConfigLoader
42
44
/// </summary>
43
45
public const string DEFAULT_CONFIG_FILE_NAME = $ "{ CONFIGFILE_NAME } { CONFIG_EXTENSION } ";
44
46
45
- public string ConfigFileName => GetFileNameForEnvironment ( Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) , false ) ;
47
+ /// <summary>
48
+ /// Stores the config file name actually loaded by the engine.
49
+ /// It could be the base config file (e.g. dab-config.json), any of its derivatives with
50
+ /// environment specific suffixes (e.g. dab-config.Development.json) or the user provided
51
+ /// config file name.
52
+ /// </summary>
53
+ public string ConfigFileName { get ; internal set ; }
46
54
47
55
public FileSystemRuntimeConfigLoader ( IFileSystem fileSystem , string baseConfigFileName = DEFAULT_CONFIG_FILE_NAME , string ? connectionString = null )
48
56
: base ( connectionString )
49
57
{
50
58
_fileSystem = fileSystem ;
51
59
_baseConfigFileName = baseConfigFileName ;
60
+ ConfigFileName = GetFileNameForEnvironment ( Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) , false ) ;
52
61
}
53
62
54
63
/// <summary>
@@ -69,6 +78,12 @@ public bool TryLoadConfig(
69
78
string json = _fileSystem . File . ReadAllText ( path ) ;
70
79
return TryParseConfig ( json , out config , connectionString : _connectionString , replaceEnvVar : replaceEnvVar ) ;
71
80
}
81
+ else
82
+ {
83
+ // Unable to use ILogger because this code is invoked before LoggerFactory
84
+ // is instantiated.
85
+ Console . WriteLine ( $ "Unable to find config file: { path } does not exist.") ;
86
+ }
72
87
73
88
config = null ;
74
89
return false ;
@@ -178,21 +193,7 @@ public static string GetEnvironmentFileName(string fileName, string environmentV
178
193
public bool DoesFileExistInCurrentDirectory ( string fileName )
179
194
{
180
195
string currentDir = _fileSystem . Directory . GetCurrentDirectory ( ) ;
181
- // Unable to use ILogger because this code is invoked before LoggerFactory
182
- // is instantiated.
183
- if ( _fileSystem . File . Exists ( _fileSystem . Path . Combine ( currentDir , fileName ) ) )
184
- {
185
- // This config file is logged as being found, but may not actually be used!
186
- Console . WriteLine ( $ "Found config file: { fileName } .") ;
187
- return true ;
188
- }
189
- else
190
- {
191
- // Unable to use ILogger because this code is invoked before LoggerFactory
192
- // is instantiated.
193
- Console . WriteLine ( $ "Unable to find config file: { fileName } does not exist.") ;
194
- return false ;
195
- }
196
+ return _fileSystem . File . Exists ( _fileSystem . Path . Combine ( currentDir , fileName ) ) ;
196
197
}
197
198
198
199
/// <summary>
@@ -251,11 +252,13 @@ public static string GetMergedFileNameForEnvironment(string fileName, string env
251
252
}
252
253
253
254
/// <summary>
254
- /// Allows the base config file name to be updated. This is commonly done when the CLI is starting up.
255
+ /// Allows the base config file and the actually loaded config file name(tracked by the property ConfigFileName)
256
+ /// to be updated. This is commonly done when the CLI is starting up.
255
257
/// </summary>
256
258
/// <param name="fileName"></param>
257
- public void UpdateBaseConfigFileName ( string fileName )
259
+ public void UpdateConfigFileName ( string fileName )
258
260
{
259
261
_baseConfigFileName = fileName ;
262
+ ConfigFileName = fileName ;
260
263
}
261
264
}
0 commit comments