We have an established pattern for creating MW service objects tied to a foreign wiki - we create a factory, create a correct LoadBalancer, and eventually create instances of a service tied to the database on a foreign wiki.
However, the config provided into the services is instantiated from MWServices::getMainConfig - thus it belongs to a local wiki. The config is just one of the dependencies we supply in, technically when creating a service for a foreign wiki, ALL it's dependencies must belong to that foreign wiki. However, I'm singling out the config as the most obviously wrong one.
I am not aware of any real issues this disparity creates, but I could imagine a whole cluster of hard-to-find bugs related to the mismatch. However, it seems like the factory pattern applied to foreign wikis is getting more and more adoption, thus we need to discuss the implications of it.
Ideally, when obtaining a service for a foreign wiki, we should obtain a whole service container belonging to a foreign wiki. The service wiring code then would get the dbDomain from the service container, and apply it to all the services it creates. That would guarantee that if we are creating a service for the foreign wiki, the config is correct, and all the dependencies are also looking into a correct database.
One important piece of the puzzle we do not have right now is the ability to quickly load the config for another domain.