How to inject an object into a service? I need to do a couple of things:

Inject guzzle's httpclient into class A
Inject class A into my service

What I've tried so far:


services:
  my_module.field_fetcher:
    class: Drupal\my_module\ClassB
    arguments: ['@my_module.obj', '@logger.factory', '@config.factory']

  my_module.obj:
    class: Drupal\my_module\ClassA
    arguments: ['@http.client']



parameters:
  my_module.http_client.config:
    base_uri: 'http://myurl.com/'

services:
  my_module.http_client:
    factory: '@http_client_factory:fromOptions'
    arguments: ['%my_module.http_client.config%']

  my_module.obj:
    class: Drupal\my_module\ClassA
    arguments: ['@my_module.http_client']

  my_module.field_fetcher:
    class: Drupal\my_module\ClassB
    arguments: ['@my_module.obj', '@logger.factory', '@config.factory']




Simple versions of classes A and B look like this:
ClassA:
&lt;?php

namespace Drupal\my_module;

use GuzzleHttp\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class A {
  
  /**
   * @var \GuzzleHttp\ClientInterface
   */
  private $httpClient;
  
  public function __construct(ClientInterface $httpClient) {
    $this-&gt;httpClient = $httpClient;
  }
}

ClassB:
&lt;?php

namespace Drupal\my_module;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Psr\Log\LoggerInterface;
use Drupal\Core\Logger\LoggerChannelFactory;

class B implements BInterface {
  
  /**
   * @var \Drupal\my_module\A
   */
  private $a;
  
  /**
   * @var \Drupal\Core\Logger\LoggerChannelFactory
   */
  private $logger;

  public function __construct(A $a, LoggerChannelFactory $logger, ConfigFactoryInterface $config) {
    $this-&gt;a = $a;
    $this-&gt;logger = $logger;
  }
  
  public static function create(ContainerInterface $container) {
    return new static(
      A::create($container),
      $container-&gt;get('my_module.obj'),
      $container-&gt;get('logger.factory')-&gt;get('my_module'),
      $container-&gt;get('config.factory')
    );
  }
}

No matter what I try, I keep running into the same issue of drupal error logs telling me that &quot;argument 1 passed to Drupal\my_module\ClassB::__construct() must be an instance of Drupal\my_module\ClassA, string given&quot;
Edit: Updated classes A and B to reflect changes suggested.
For this my_module.services.yml file:
services:
  my_module.obj:
    class: Drupal\my_module\ClassA
    arguments: ['@http.client']

You can discard the create() method from your A class, because you declared it as a service for which the arguments get resolved by the services YAML file parameters ie. '@http_client':
class A implements AInterface {
  
  /**
   * @var \GuzzleHttp\ClientInterface
   */
  private $httpClient;
  
  /**
   * @param \GuzzleHttp\ClientInterface $http_client
   *   A Guzzle client object.
   */
  public function __construct(ClientInterface $http_client) {
    $this-&gt;httpClient = $http_client;
  }


argument 1 passed to Drupal\my_module\ClassB::__construct() must be an instance of Drupal\my_module\ClassA, string given

Fix this by correcting your B class create() method to pass your service A name being 'my_module.obj', which would then in turn correctly pass an instance to the constructor of class B:
class B implements ContainerInjectionInterface {
  
  /**
   * @var \Drupal\my_module\AInterface
   */
  private $a;

  /**
   * @var \Drupal\Core\Logger\LoggerChannelFactory
   */
  private $logger;

  /**
   * @param \Drupal\my_module\AInterface
   *   Your module A class.
   */
  public function __construct(AInterface $a, LoggerChannelFactory $logger, ConfigFactoryInterface $config) {
    $this-&gt;a = $a;
    $this-&gt;logger = $logger;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container-&gt;get('my_module.obj'),
      $container-&gt;get('logger.factory')-&gt;get('my_module'),
      $container-&gt;get('config.factory')
    );
  }