title: NestJS: UseGuards Doesn't Use Dependency Injection - Can't Override Guard
body: <h2>Current behavior</h2>
  <p>The documentation states <a href="https://docs.nestjs.com/guards#binding-guards" rel="nofollow noreferrer">here</a> that:</p>
  <blockquote>
  <p>...we passed the RolesGuard type (instead of an instance), leaving responsibility for instantiation to the framework and enabling dependency injection.</p>
  </blockquote>
  <p>So I'm expecting to &quot;override&quot; a guard with another, via the module's <code>providers</code>.
  This doesn't work as expected.</p>
  <p>Interestingly enough,
  injecting the same service via the controller's constructor does yield the correct service, though.</p>
  <h2>Input Code</h2>
  <p>Simple: <a href="https://github.com/dima-gusyatiner/nestjs-guards-override/tree/only-app-module" rel="nofollow noreferrer">https://github.com/dima-gusyatiner/nestjs-guards-override/tree/only-app-module</a></p>
  <p>With Another module, using <code>exports</code>: <a href="https://github.com/dima-gusyatiner/nestjs-guards-override/tree/master" rel="nofollow noreferrer">https://github.com/dima-gusyatiner/nestjs-guards-override/tree/master</a></p>
  <p>Controller:</p>
  <pre><code>@Controller()
  @UseGuards(AuthGuard)
  </code></pre>
  <p>Module:</p>
  <pre><code>@Module({
    controllers: [AppController],
    providers: [
      {
        provide: AuthGuard,
        useClass: AuthOverrideGuard,
      }
    ],
  })
  </code></pre>
  <h2>Expected behavior</h2>
  <p>I would expect <code>AuthGuard</code> to never even be constructed.
  Instead, both classes are constructed, and <code>AuthGuard</code> is used as the guard.</p>
  <h2>Environment</h2>
  <pre><code>- Nest version: 8.0.6
  - Node version: 16.8.0
  - Platform: Linux</code></pre>
  <h2>Bug Report</h2>
  <p>I've also opened a ticket for this:
  <a href="https://github.com/nestjs/nest/issues/8011" rel="nofollow noreferrer">https://github.com/nestjs/nest/issues/8011</a></p>
  <h2>Question</h2>
  <p>Am I doing something wrong here, or is this a bug?
  Anybody can suggest a workaround?</p>