Thread:Talk:Requests for comment/TitleValue/ServiceRegistry singleton/reply (3)

You are right that the ServiceRegistry is again bundling all the services in a single object. The point is to restrict access to ServiceRegistry to "bootstrapping code" (e.g. in static hook handlers) only. RequestContext is used all over the code, so all the code is dependent on anything in the RequestContext. That makes me very very reluctant to add more stuff to it.

You are right about life time control. Essentially, I think about it this way:
 * code that uses global state is not testable with unit tests
 * so, try hard to avoid any access to global state
 * and isolate the code that does need such access

In the example, the static onSomeHook would not be covered by unit tests, because it relies on global state (via Registry::getDefaultInstance or RequestContext::getMain, it doesn't matter). But the MySomeHookHandler could be fully tested, without elaborate fixtures or leaking state.