@@ -31,7 +31,7 @@ public abstract class OutOfProcessNodeJSService : INodeJSService
3131 private readonly IEmbeddedResourcesService _embeddedResourcesService ;
3232 private readonly ITaskService _taskService ;
3333 private readonly IBlockDrainerService _blockDrainerService ;
34- private readonly IFileWatcherFactory _fileWatcherFactory ;
34+ private readonly IFileWatcherService _fileWatcherService ;
3535 private readonly INodeJSProcessFactory _nodeProcessFactory ;
3636 private readonly string _serverScriptName ;
3737 private readonly Assembly _serverScriptAssembly ;
@@ -48,7 +48,6 @@ public abstract class OutOfProcessNodeJSService : INodeJSService
4848
4949 private bool _disposed ;
5050 private volatile INodeJSProcess ? _nodeJSProcess ; // Volatile since it's used in a double checked lock
51- private IFileWatcher ? _fileWatcher ;
5251
5352 /// <summary>
5453 /// <para>This regex is used to determine successful initialization of the process.</para>
@@ -63,7 +62,7 @@ public abstract class OutOfProcessNodeJSService : INodeJSService
6362 /// <param name="logger"></param>
6463 /// <param name="optionsAccessor"></param>
6564 /// <param name="embeddedResourcesService"></param>
66- /// <param name="fileWatcherFactory "></param>
65+ /// <param name="fileWatcherService "></param>
6766 /// <param name="taskService"></param>
6867 /// <param name="blockDrainerService"></param>
6968 /// <param name="serverScriptAssembly"></param>
@@ -72,13 +71,13 @@ protected OutOfProcessNodeJSService(INodeJSProcessFactory nodeProcessFactory,
7271 ILogger logger ,
7372 IOptions < OutOfProcessNodeJSServiceOptions > optionsAccessor ,
7473 IEmbeddedResourcesService embeddedResourcesService ,
75- IFileWatcherFactory fileWatcherFactory ,
74+ IFileWatcherService fileWatcherService ,
7675 ITaskService taskService ,
7776 IBlockDrainerService blockDrainerService ,
7877 Assembly serverScriptAssembly ,
7978 string serverScriptName )
8079 {
81- _fileWatcherFactory = fileWatcherFactory ;
80+ _fileWatcherService = fileWatcherService ;
8281 _taskService = taskService ;
8382 _blockDrainerService = blockDrainerService ;
8483
@@ -383,13 +382,6 @@ internal virtual async ValueTask ConnectIfNotConnectedAsync(CancellationToken ca
383382 return ;
384383 }
385384
386- // No need to listen for file events while connecting - the new NodeJS process will reload all files.
387- if ( _debugLoggingEnabled )
388- {
389- Logger . LogDebug ( string . Format ( Strings . LogDebug_OutOfProcessNodeJSService_StoppingFileWatcher , _nodeJSProcess ? . SafeID ) ) ;
390- }
391- _fileWatcher ? . Stop ( ) ;
392-
393385 await CreateNewProcessAndConnectAsync ( ) . ConfigureAwait ( false ) ;
394386 }
395387 finally
@@ -458,7 +450,6 @@ internal virtual async Task CreateNewProcessAndConnectAsync()
458450 {
459451 Logger . LogDebug ( string . Format ( Strings . LogDebug_OutOfProcessNodeJSService_StartingFileWatcher , _nodeJSProcess . SafeID ) ) ;
460452 }
461- _fileWatcher ? . Start ( ) ;
462453
463454 _nodeJSProcess . SetConnected ( ) ;
464455
@@ -533,7 +524,7 @@ internal virtual (bool trackInvokeTasks, ConcurrentDictionary<Task, object?> tra
533524 return default ;
534525 }
535526
536- _fileWatcher = _fileWatcherFactory . Create ( _options . WatchPath , _options . WatchSubdirectories , _options . WatchFileNamePatterns , FileChangedHandler ) ;
527+ _fileWatcherService . AddFileChangedListenerAsync ( FileChangedHandler ) ;
537528
538529 if ( ! _options . GracefulProcessShutdown )
539530 {
@@ -578,19 +569,12 @@ internal virtual (bool trackInvokeTasks, ConcurrentDictionary<Task, object?> tra
578569 }
579570
580571 // FileSystemWatcher handles file events synchronously (one after another), storing pending events in a buffer - https://github.com/dotnet/runtime/blob/master/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Win32.cs.
581- internal virtual void FileChangedHandler ( string path )
572+ internal virtual void FileChangedHandler ( )
582573 {
583- if ( _infoLoggingEnabled )
584- {
585- Logger . LogInformation ( string . Format ( Strings . LogInformation_FileChangedMovingtoNewNodeJSProcess , path ) ) ;
586- }
587-
588- // Immediately stop the fileWatcher so we don't get redundant events (see FileWatcher.Stop)
589574 if ( _debugLoggingEnabled )
590575 {
591- Logger . LogDebug ( string . Format ( Strings . LogDebug_OutOfProcessNodeJSService_StoppingFileWatcher , _nodeJSProcess ? . SafeID ) ) ;
576+ Logger . LogDebug ( string . Format ( Strings . LogDebug_FileChangedHandlerInvokedForProcess , _nodeJSProcess ? . SafeID ) ) ;
592577 }
593- _fileWatcher ? . Stop ( ) ;
594578
595579#pragma warning disable CS4014
596580 // No need to await
@@ -760,7 +744,6 @@ protected virtual void Dispose(bool disposing)
760744 if ( disposing )
761745 {
762746 _nodeJSProcess ? . Dispose ( ) ;
763- _fileWatcher ? . Dispose ( ) ;
764747 _connectingLock ? . Dispose ( ) ;
765748 _blockDrainerService ? . Dispose ( ) ;
766749 }
0 commit comments