I'm developing an "indexing service" (as part of a WPF application) that will run on a background thread, and use a FileSystemWatcher to monitor some files. When the file contents change I want to extract some information and update a Lucene index. Occasionally the user may wish to perform a search against the index.
Should I create an index reader every time the user performs a search? And a writer every time the indexes are updated? Or is it okay for my indexing service class (which is a singleton) to have singleton reader and writer instances (plus a singleton FSDirectory, that they both have a dependency on)?
If I was to use singleton instances, do I need to worry about closing/disposing them? If so, should my indexing service implement IDisposable
, and do the cleanup in Dispose()
?