Search code examples
nservicebusfilesystemwatcher

How do I send an NServiceBus message when a file is created?


I know how to use the FileSystemWatcher class, and I know how to send the message I want to send. What I can't figure out is where to initialize the FileSystemWatcher.

I'm assuming that there's some place to initialize an Endpoint where I could set this up, but I'm not certain where that would be.

Seems like this would be a common use-case; I'm a little surprised that Udi hasn't built this into NServiceBus!


Solution

  • Yes that is built into NServiceBus.

    You need to implement a class that derives from IWantToRunWhenBusStartsAndStops.
    See http://docs.particular.net/nservicebus/the-nservicebus-host#custom-initialization-and-startup for more info.