X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=docs%2Finjection.txt;h=83a14c730dcc1662c5f54f6cfca18eeeee85372e;hb=31c334794c8164e44353e22aed71bb27caca80e3;hp=e0466c44a55fbd11da80e942ac3d9af865120c15;hpb=a0803c9bc551631c8a35bf2d99705a724cb62039;p=lhc%2Fweb%2Fwiklou.git diff --git a/docs/injection.txt b/docs/injection.txt index e0466c44a5..83a14c730d 100644 --- a/docs/injection.txt +++ b/docs/injection.txt @@ -60,6 +60,27 @@ MediaWikiServices::getInstance() should ideally be accessed only in "static entry points" such as hook handler functions. See "Migration" below. +== Service Reset == + +Services get their configuration injected, and changes to global +configuration variables will not have any effect on services that were already +instantiated. This would typically be the case for low level services like +the ConfigFactory or the ObjectCacheManager, which are used during extension +registration. To address this issue, Setup.php resets the global service +locator instance by calling MediaWikiServices::resetGlobalInstance() once +configuration and extension registration is complete. + +Note that "unmanaged" legacy services services that manage their own singleton +must not keep references to services managed by MediaWikiServices, to allow a +clean reset. After the global MediaWikiServices instance got reset, any such +references would be stale, and using a stale service will result in an error. + +Services should either have all dependencies injected and be themselves managed +by MediaWikiServices, or they should use the Service Locator pattern, accessing +service instances via the global MediaWikiServices instance state when needed. +This ensures that no stale service references remain after a reset. + + == Configuration == When the default MediaWikiServices instance is created, a Config object is @@ -198,7 +219,7 @@ already known to MediaWikiServices (if not, see above). variables. * Add a constructor to MyExtHooks that takes a Bar service as a parameter. * Add a static method called newFromGlobalState() with no parameters. It should - just return new MyExtHooks( MediaWikiServices::getBar() ). + just return new MyExtHooks( MediaWikiServices::getInstance()->getBar() ). * The original static handler method onFoo( $x ) is then implemented as self::newFromGlobalState()->doFoo( $x ).