Skip to content

Better docs for implicit request scoped providers #2945

Closed
@StiliyanKushev

Description

@StiliyanKushev

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

I believe the docs never mention the implicit behavior of a provider automatically becoming request scoped if it injects the REQUEST token in its constructor.

import { Inject, Injectable, Scope } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';

// @Injectable({ scope: Scope.REQUEST })
@Injectable() // the provider still becomes request scoped
export class MyProviderClass {
  constructor(
    @Inject(REQUEST) // 👈
    private readonly requestContext: unknown,
  ) {}
}

Describe the solution you'd like

I'd like to see this mentioned in the official docs if it's expected behavior.

Teachability, documentation, adoption, migration strategy

Alternatively, have nest throw an error (or at least a warning) in such cases if it's not expected behavior.

What is the motivation / use case for changing the behavior?

IMO, this is rather unintuitive at a first glance, and may potentially cause confusion.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions