title: Getting "inject() must be called from an injection context" after upgrading to Angular 11
body: <p>After upgrading to Angular 11, I am not able to <code>ng serve</code> my web application anymore.</p>
  <p>I am generating the client using Spring Doc and the latest OpenAPI generator gradle-plutin (5.0.0).</p>
  <p>The problem appears to be related to my (generated) REST-client. Opening https://localhost:4200 will write the following into the console:</p>
  <pre><code>main.ts:12 Error: inject() must be called from an injection context
      at injectInjectorOnly (core.js:4901) [angular]
      at Module.ɵɵinject (core.js:4911) [angular]
      at Object.ApiModule_Factory [as factory] (meditation-rest-client.js:2885) [angular]
      at R3Injector.hydrate (core.js:11158) [angular]
      at R3Injector.get (core.js:10979) [angular]
      at :4200/vendor.js:82591:55 [angular]
      at Set.forEach (&lt;anonymous&gt;) [angular]
      at R3Injector._resolveInjectorDefTypes (core.js:11016) [angular]
      at new NgModuleRef$1 (core.js:25046) [angular]
      at NgModuleFactory$1.create (core.js:25100) [angular]
      at :4200/vendor.js:100468:45 [angular]
      at Object.onInvoke (core.js:28301) [angular]
  </code></pre>
  <p>The following is my <code>tsconfig.json</code> file:</p>
  <pre class="lang-json prettyprint-override"><code>/* To learn more about this file see: https://angular.io/config/tsconfig. */
  {
    &quot;compileOnSave&quot;: false,
    &quot;compilerOptions&quot;: {
      &quot;baseUrl&quot;: &quot;./&quot;,
      &quot;outDir&quot;: &quot;./dist/out-tsc&quot;,
      &quot;sourceMap&quot;: true,
      &quot;declaration&quot;: false,
      &quot;downlevelIteration&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;importHelpers&quot;: true,
      &quot;target&quot;: &quot;es2015&quot;,
      &quot;module&quot;: &quot;es2020&quot;,
      &quot;lib&quot;: [
        &quot;es2018&quot;,
        &quot;dom&quot;
      ]
    }
  }
  </code></pre>
  <p>This is how I define the dependency in <code>package.json</code></p>
  <pre class="lang-json prettyprint-override"><code>    &quot;chart.js&quot;: &quot;^2.9.4&quot;,
      &quot;core-js&quot;: &quot;^3.8.2&quot;,
      &quot;meditation-rest-client&quot;: &quot;./generated/meditation-rest-client&quot;,
      &quot;http-server&quot;: &quot;^0.12.3&quot;,
      &quot;http-status-codes&quot;: &quot;^2.1.4&quot;,
      &quot;moment&quot;: &quot;^2.29.1&quot;,
  </code></pre>
  <p>And this here are those generated lines which are reffered to in the error message above:</p>
  <pre class="lang-js prettyprint-override"><code>// ...
  
  ApiModule.ɵmod = ɵngcc0.ɵɵdefineNgModule({ type: ApiModule });
  ApiModule.ɵinj = ɵngcc0.ɵɵdefineInjector({ factory: function ApiModule_Factory(t) { return new (t || ApiModule)(ɵngcc0.ɵɵinject(ApiModule, 12), ɵngcc0.ɵɵinject(ɵngcc1.HttpClient, 8)); }, providers: [], imports: [[]] });
  ApiModule.ctorParameters = () =&gt; [
      { type: ApiModule, decorators: [{ type: Optional }, { type: SkipSelf }] },
      { type: HttpClient, decorators: [{ type: Optional }] }
  ];
  
  // ...
  </code></pre>
  <p>This used to work in Angular 9 but it won't under Angular 11.</p>
  <p>Any idea how to fix this? I already tried setting <code>&quot;preserveSymlinks&quot;: true</code> as suggested <a href="https://github.com/angular/angular/issues/25813" rel="noreferrer">here</a> and <a href="https://github.com/OpenAPITools/openapi-generator/issues/5246" rel="noreferrer">here</a>.</p>
  <p>Please let me know if you need more information.</p>