From d726cdfd3de1ba2f0b0b28237ef153460566617e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 22 Jan 2024 23:05:26 +0100 Subject: Injection.md: Improve advice about replacing wfGetDB() Change-Id: Ic9b3208f736ef90639c10d0efabaa7f4e8d970db --- docs/Injection.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'docs/Injection.md') diff --git a/docs/Injection.md b/docs/Injection.md index 850a96ce6b7a..b92e54c4d8a9 100644 --- a/docs/Injection.md +++ b/docs/Injection.md @@ -169,10 +169,11 @@ Assume `Foo` is a class that uses the `$wgScriptPath` global and calls `wfGetDB()` to get a database connection, in non-static methods. * Add `$scriptPath` as a constructor parameter and use `$this->scriptPath` instead of `$wgScriptPath`. -* Add LoadBalancer `$dbLoadBalancer` as a constructor parameter. Use - `$this->dbLoadBalancer->getConnection()` instead of `wfGetDB()`. +* Add IConnectionProvider `$dbProvider` as a constructor parameter. Use + `$this->dbProvider->getReplicaDatabase()` instead of `wfGetDB( DB_REPLICA )`, + `$this->dbProvider->->getPrimaryDatabase()` instead of `wfGetDB( DB_PRIMARY )`. * Any code that calls `Foo`'s constructor would now need to provide the - `$scriptPath` and `$dbLoadBalancer`. To avoid this, avoid direct instantiation + `$scriptPath` and `$dbProvider`. To avoid this, avoid direct instantiation of services all together - see below. ### Migrate services with multiple configuration variables @@ -347,9 +348,9 @@ For this purpose, `Thingy` uses wfGetDB(). record's data with a single `ThingyRecord` object. * In the old Thingy class, replace all calls to static methods or functions, such as wfGetDB(), with calls to the appropriate services, such as - `LoadBalancer::getConnection()`. + `IConnectionProvider::getReplicaDatabase()`. * In Thingy's constructor, pull in any services needed, such as the - LoadBalancer, by using `MediaWikiServices::getInstance()`. These services + IConnectionProvider, by using `MediaWikiServices::getInstance()`. These services cannot be injected without changing the constructor signature, which is often impractical for "smart records" that get instantiated directly in many places in the code base. -- cgit v1.2.3