Issue #3395176: only run menu rebuild outside maintenance mode. And use dependency injection for services.
Closes #3395176