Error: Maximum function nesting level of '512' reached when injecting custom service to webform (6.x) handler I'm trying to use my custom service in the handler like this (in webform 6.0-beta1):
class TriggerAutomationWebformHandler extends WebformHandlerBase {

  /**
   * Ecomail.
   *
   * @var \Drupal\ecomail_automation\EcomailInterface
   */
  protected $ecomail;

  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
    $instance-&gt;ecomail = $container-&gt;get('ecomail_automation.ecomail');
  }
?&gt;

mymodule.services.yml file looks like this:
services:
  ecomail_automation.ecomail:
    class: Drupal\ecomail_automation\Ecomail
    arguments: [ '@config.factory', '@logger.factory' ]

My Drupal\ecomail_automation\Ecomail class in constructed like this (\Ecomail class is different class in a global namespace - see https://packagist.org/packages/ecomailcz/ecomail):
  public function __construct(ConfigFactoryInterface $config, LoggerChannelFactoryInterface $logger_factory) {
    $this-&gt;config = $config-&gt;get('ecomail_webform.settings');
    $this-&gt;logger = $logger_factory;
    $this-&gt;ecomail = new \Ecomail($this-&gt;config-&gt;get('api_key'));
  }
?&gt;

This leads to error (shortened to important parts):
Error: Maximum function nesting level of '512' reached, aborting! in Drupal\Component\Plugin\PluginBase-&gt;__construct() (line 53 of core/lib/Drupal/Component/Plugin/PluginBase.php).

Drupal\Component\Plugin\PluginBase-&gt;__construct(Array, 'trigger_automation', Array) (Line: 141)
Drupal\webform\Plugin\WebformHandlerBase::create(Object, Array, 'trigger_automation', Array) (Line: 43)
Drupal\ecomail_automation\Plugin\WebformHandler\TriggerAutomationWebformHandler::create(Object, Array, 'trigger_automation', Array) (Line: 21)
Drupal\Core\Plugin\Factory\ContainerFactory-&gt;createInstance('trigger_automation', Array) (Line: 76)
Drupal\Component\Plugin\PluginManagerBase-&gt;createInstance('trigger_automation', Array) (Line: 81)
Drupal\Core\Plugin\DefaultLazyPluginCollection-&gt;initializePlugin('trigger_automation') (Line: 35)
Drupal\webform\Plugin\WebformHandlerPluginCollection-&gt;initializePlugin('trigger_automation') (Line: 80)
Drupal\Component\Plugin\LazyPluginCollection-&gt;get('trigger_automation') (Line: 40)
Drupal\webform\Plugin\WebformHandlerPluginCollection-&gt;initializePlugin('trigger_automation') (Line: 80)
Drupal\Component\Plugin\LazyPluginCollection-&gt;get('trigger_automation') (Line: 40)
Drupal\webform\Plugin\WebformHandlerPluginCollection-&gt;initializePlugin('trigger_automation') (Line: 80)
Drupal\Component\Plugin\LazyPluginCollection-&gt;get('trigger_automation') (Line: 40)
...

What am I doing wrong?
The problem is that you're instanciating the Ecomail object into your Ecomail constructor $this-&gt;ecomail = new \Ecomail($this-&gt;config-&gt;get('api_key')); which is kind of a fork bomb.
Your Ecomail is creating an Ecomail itself creating another Ecomail, etc.
That's an infinite loop