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

The reason I suggest using RequestContext is for lifetime control. If you store an instance in a static variable, you are stuck with infinite lifetime, even beyond the end of a unit test unless you add special teardown code. And if bundling all services into a single object is bad, maybe I misunderstand the role of ServiceRegistry? I thought your proposed ServiceRegistry was a bundle of all service objects, that seemed to be implied by its name.

What I'm proposing is that the calling code would be similar:

public static final onSomeHook( $stuff ) { $someService = RequestContext::getMain->getServiceRegistry->getSomeService;

Or even identical:

class ServiceRegistry { static function getDefaultInstance { return RequestContext::getMain->getServiceRegistry->getSomeService; } }