Using symfony service closures causes fatal error
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3579658. -->
Reported by: [grevil](https://www.drupal.org/user/3668491)
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>When using symfony service closures to inject services into a class, webprofiler tries to inject the actual (wrapped) service into the class, instead of the service closure causing the following fatal error:</p>
<blockquote><p>The website encountered an unexpected error. Try again later.<br>
TypeError: Drupal\ban\BanMiddleware::__construct(): Argument #3 ($config_factory_closure) must be of type ?Closure, Drupal\webprofiler\Config\ConfigFactoryWrapper given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in Drupal\ban\BanMiddleware->__construct() (line 48 of modules/custom/ban/src/BanMiddleware.php).<br>
Drupal\ban\BanMiddleware->__construct() (Line: 259)<br>
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)<br>
Drupal\Component\DependencyInjection\Container->get() (Line: 426)<br>
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)<br>
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)<br>
Drupal\Component\DependencyInjection\Container->get() (Line: 426)<br>
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)<br>
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)<br>
Drupal\Component\DependencyInjection\Container->get() (Line: 426)<br>
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)<br>
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)<br>
Drupal\Component\DependencyInjection\Container->get() (Line: 426)<br>
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)<br>
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)<br>
Drupal\Component\DependencyInjection\Container->get() (Line: 426)<br>
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)<br>
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)<br>
Drupal\Component\DependencyInjection\Container->get() (Line: 426)<br>
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)<br>
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)<br>
Drupal\Component\DependencyInjection\Container->get() (Line: 1587)<br>
Drupal\Core\DrupalKernel->getHttpKernel() (Line: 745)<br>
Drupal\Core\DrupalKernel->handle() (Line: 19)</p></blockquote>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ul>
<li>Enable the ban module and use the provided patch in <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-17"><a href="https://www.drupal.org/project/ban/issues/3579646" title="Status: Closed (outdated)">#3579646: Injecting the config factory inside the middleware causes performance hit</a></span> (the issue is not merged at the time of writing, otherwise it can be simply tested in ban 1.1.x).</li>
<li>Enable webprofiler.</li>
<li>The fatal error appears on every site call.</li>
</ul>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3 id="summary-ui-changes">User interface changes</h3>
<h3 id="summary-api-changes">API changes</h3>
<h3 id="summary-data-model-changes">Data model changes</h3>
> Related issue: [Issue #3579646](https://www.drupal.org/node/3579646)
issue