Use dependency injection for key watcher
This refactors the Workhorse "key watcher" code to use dependency injection instead of global variables. The change is broken down in 3 commits which can be reviewed separately.
This MR causes no change in observable behavior of the application.