The Service Container has a great deal of flexibility when it comes to instantiating your service. Sometimes, however, this does not provide everything necessary to construct the service. When you need more specific control over this process, you can define a factory to instantiate the service. There are two ways to define this factory. First, you can define a factory service and define the function on that service to invoke:
http_client:
class: GuzzleHttp\Client
factory: http_client_factory:fromOptions
In this case, the class defined by the http_client_factory service has a member function, fromOptions(), that returns a GuzzleHttp\Client object.
The other option is to define the factory as a static function:
http_handler_stack:
class: GuzzleHttp\HandlerStack
public: false
factory: GuzzleHttp\HandlerStack::create
configurator: ['@http_handler_stack_configurator', configure]
To instantiate an http_handler_stack service, the static function on the GuzzleHttp\HandlerStack class will be invoked.