@@ -90,7 +90,8 @@ public sealed class CrudApiPlugin(
9090 proxyConfiguration ,
9191 pluginConfigurationSection )
9292{
93- private CrudApiDefinitionLoader ? _loader ;
93+ private CrudApiDefinitionLoader ? _definitionLoader ;
94+ private CrudApiDataLoader ? _dataLoader ;
9495 private JArray ? _data ;
9596 private OpenIdConnectConfiguration ? _openIdConnectConfiguration ;
9697
@@ -104,8 +105,8 @@ public override async Task InitializeAsync(InitArgs e, CancellationToken cancell
104105
105106 Configuration . ApiFile = ProxyUtils . GetFullPath ( Configuration . ApiFile , ProxyConfiguration . ConfigFile ) ;
106107
107- _loader = ActivatorUtilities . CreateInstance < CrudApiDefinitionLoader > ( e . ServiceProvider , Configuration ) ;
108- await _loader . InitFileWatcherAsync ( cancellationToken ) ;
108+ _definitionLoader = ActivatorUtilities . CreateInstance < CrudApiDefinitionLoader > ( e . ServiceProvider , Configuration ) ;
109+ await _definitionLoader . InitFileWatcherAsync ( cancellationToken ) ;
109110
110111 if ( Configuration . Auth == CrudApiAuthType . Entra &&
111112 Configuration . EntraAuthConfig is null )
@@ -126,7 +127,13 @@ public override async Task InitializeAsync(InitArgs e, CancellationToken cancell
126127 return ;
127128 }
128129
129- LoadData ( ) ;
130+ _dataLoader = ActivatorUtilities . CreateInstance < CrudApiDataLoader > (
131+ e . ServiceProvider ,
132+ Configuration ,
133+ ( Action < JArray ? > ) ( data => _data = data )
134+ ) ;
135+ await _dataLoader . InitFileWatcherAsync ( cancellationToken ) ;
136+
130137 await SetupOpenIdConnectConfigurationAsync ( ) ;
131138 }
132139
@@ -200,27 +207,6 @@ private async Task SetupOpenIdConnectConfigurationAsync()
200207 }
201208 }
202209
203- private void LoadData ( )
204- {
205- try
206- {
207- var dataFilePath = Path . GetFullPath ( ProxyUtils . ReplacePathTokens ( Configuration . DataFile ) , Path . GetDirectoryName ( Configuration . ApiFile ) ?? string . Empty ) ;
208- if ( ! File . Exists ( dataFilePath ) )
209- {
210- Logger . LogError ( "Data file '{DataFilePath}' does not exist. The {APIUrl} API will be disabled." , dataFilePath , Configuration . BaseUrl ) ;
211- Configuration . Actions = [ ] ;
212- return ;
213- }
214-
215- var dataString = File . ReadAllText ( dataFilePath ) ;
216- _data = JArray . Parse ( dataString ) ;
217- }
218- catch ( Exception ex )
219- {
220- Logger . LogError ( ex , "An error has occurred while reading {ConfigFile}" , Configuration . DataFile ) ;
221- }
222- }
223-
224210 private ( Action < SessionEventArgs , CrudApiAction , IDictionary < string , string > > handler , CrudApiAction action , IDictionary < string , string > parameters ) ? GetMatchingActionHandler ( Request request )
225211 {
226212 if ( Configuration . Actions is null ||
0 commit comments