Form textfield AJAX validation "deletes" injected services to form I'm trying to create a form that has two services injected (for access to an API) and a textfield with an AJAX callback. Here it is:
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['vat_number'] = [
        '#title' =&gt; $this-&gt;t('VAT Number'),
        '#type' =&gt; 'textfield',
        '#default_value' =&gt; isset($address['vat_number']) ? $address['vat_number'] : '',
        '#states' =&gt; [
          'visible' =&gt; [
            ':input[name=&quot;is_business&quot;]' =&gt; ['checked' =&gt; TRUE],
          ],
          'required' =&gt; [
            ':input[name=&quot;is_business&quot;]' =&gt; ['checked' =&gt; TRUE],
          ],
        ],
        '#ajax' =&gt; [
          'callback' =&gt; '::validateVatAjax',
          'event' =&gt; 'change',
          'url' =&gt; Url::fromRoute('shop_product.digital_river_payment_form'),
          'options' =&gt; [
            'query' =&gt; [
              FormBuilderInterface::AJAX_FORM_REQUEST =&gt; TRUE,
            ],
          ],
        ],
        '#suffix' =&gt; '&lt;/div&gt;',
      ];
    }
.....
}
public function validateVatAjax(array &amp;$form, FormStateInterface $form_state) {$response = new AjaxResponse();
    $message = '&lt;div id=&quot;errors&quot; class=&quot;alert alert-danger&quot; role=&quot;alert&quot;&gt;';

    if (!$this-&gt;customerService-&gt;validateCustomerTaxFormat($form_state-&gt;getValue('vat_number'))) {
      $message .= $this-&gt;customerService-&gt;$schema['properties']['value']['description'];
      $message .= '&lt;/div&gt;';
    }
    else {
      $message = '&lt;div id=&quot;errors&quot; class=&quot;alert alert-danger hide&quot; role=&quot;alert&quot;&gt;&lt;/div&gt;';
    }
    $response-&gt;addCommand(new ReplaceCommand('#errors', $message));
    $form_state-&gt;setRebuild(FALSE);
    return $response;
  }

public function validateForm(array &amp;$form, FormStateInterface $form_state) {
if ($form_state-&gt;getValue('is_business') == 1) {
        $vat_number = $form_state-&gt;getValue('vat_number');
        if (empty($vat_number)) {
          $form_state-&gt;setErrorByName('vat_number', $this-&gt;t('Please enter your tax number.'));
        }
        elseif (!$this-&gt;customerService-&gt;validateCustomerTaxFormat($form_state-&gt;getValue('vat_number'))) {
          $schema = $this-&gt;customerService-&gt;getSchema();
            $form_state-&gt;setErrorByName('vat_number', $schema['properties']['value']['description']);
          }
          else {
            $form_state-&gt;setErrorByName('vat_number', $this-&gt;t('Please enter your VAT number including the two letter country code.'));
          }
        }
      }
}

I omitted some of the code but my problem is that on the second AJAX call to the callback, it fails because the customerService is null. Aside from that, I don't understand why validateForm() is called on the textfield input change. Is this normal for Drupal?
Thanks in advance.
For anyone running into this problem or AJAX call that fails on the second call intermittently, check the properties used on your AJAX form class for the right access. It seems a trivial thing but change the properties of DInjected services to protected. Refrain from using private as the dependency serialization from Drupal won't be able to get those for caching purposes.
Check this link for more information.