Dependency inject a class with values from a config object? Is it possible to DI dependencies in Drupal 8 but initialize it with values from a config object?

For example, SoapClient requires specifying the WSDL when called. I have different WSDL URLs depending on what environment I am using (test/prod etc). 

I know you can do this from the services yaml file, but I have not read of a way where you can reference a value or value(s) from a config object.

My ultimate goal is to create a decorator or factory for SoapClient, but I'm not sure which.

edit: updated with code.

An interface:

&lt;?php

namespace Drupal\iana_netforum_auth\Factory;

use SoapClient;

interface SoapClientFactoryInterface {

  /**
   * Create a SoapClient.
   *
   * This method should prepopulate the SoapClient with values from our
   * module configuration so it is ready to use.
   *
   * @return SoapClient
   */
  public function create() : SoapClient;

}


The factory:

&lt;?php

namespace Drupal\iana_netforum_auth\Factory;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\iana_netforum_auth\Exception\NetforumException;
use SoapClient;

class SoapClientFactory implements SoapClientFactoryInterface {

  public function __construct(ConfigFactoryInterface $config_factory) {
    $this-&gt;configFactory = $config_factory;
  }

  public function create() : SoapClient {
    $config = $this-&gt;configFactory-&gt;get('iana_netforum_auth.settings');
    $arguments = [];

    try {
      if ($config-&gt;get('mode') == 'live') {
        $endpoint = $config-&gt;get('live_endpoint');
      }
      else {
        $endpoint = $config-&gt;get('dev_endpoint');
        $arguments = [
          'trace' =&gt; $config-&gt;get('enable_trace'),
          'exceptions' =&gt; $config-&gt;get('enable_exceptions')
        ];
      }

      return new SoapClient($endpoint, $arguments);
    }
    catch (SoapFault $error) {
      throw new NetforumException('Invalid WSDL endpoint specified.');
    }
  }

}


The class:

class NetforumClient implements NetforumClientInterface {

  protected $username;
  protected $password;
  protected $token;
  protected $authorizationHeaders;

  /**
   * Drupal\Core\Config\ConfigFactoryInterface definition.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Drupal\iana_netforum_auth\Factory\SoapClientFactoryInterface definition.
   *
   * @var \Drupal\iana_netforum_auth\Factory\SoapClientFactoryInterface
   */
  protected $soapClient;

  /**
   * Class constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   An instance of ConfigFactoryInterface.
   * @param \Drupal\iana_netforum_auth\Factory\SoapClientFactoryInterface $soap_client_factory
   *   An instance of SoapClientFactoryInterface.
   */
  public function __construct(ConfigFactoryInterface $config_factory, SoapClientFactoryInterface $soap_client_factory) {
    $this-&gt;configFactory = $config_factory;
    $this-&gt;soapClient = $soap_client_factory-&gt;create();
  }
Not sure which part exactly is unclear. There are lots of examples in core.services.yaml that inject the config.factory service to read a configuration object, for example this:

diff.formatter:
  class: Drupal\Core\Diff\DiffFormatter
  arguments: ['@config.factory']


The constructor for that then looks like this:

/**
 * Creates a DiffFormatter to render diffs in a table.
 *
 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
 *   The config factory.
 */
public function __construct(ConfigFactoryInterface $config_factory) {
  $config = $config_factory-&gt;get('system.diff');
  $this-&gt;leading_context_lines = $config-&gt;get('context.lines_leading');
  $this-&gt;trailing_context_lines = $config-&gt;get('context.lines_trailing');
}


Once you have the config object, you get the configuration you want and pass it along to the SoapClient constructor.