Assuming that you build your service (your code looks like a service) you will probably instantiate it in a service factory (in this case I've put it in the module config):
class MyModule
{
public function getServiceConfig()
{
return array(
'factories' => array(
'my_request_object' => function (
\Zend\ServiceManager\ServiceLocatorInterface $sl
) {
$config = $sl->get('config');
return new \GaGooGl\Http\Request($config);
},
),
);
}
}
This way, you are injecting the config object directly in its consumer (without having a reference to the service locator in the consumer)
Another way is to implement Zend\ServiceManager\ServiceLocatorAwareInterface
in your GaGooGl\Http\Request
. I personally discourage it, but this basically allows you to have your Request
object keep a reference to the service locator internally, therefore making it possible to retrieve the config
service at runtime.