docs.nestjs.com icon indicating copy to clipboard operation
docs.nestjs.com copied to clipboard

Proposal: Information about change of injection token generation (introduced in v8)

Open Flusinerd opened this issue 2 years ago • 1 comments

I'm submitting a...

  • [ ] Regression
  • [ ] Bug report
  • [ ] Feature request
  • [x] Documentation issue or request (new chapter/page)
  • [ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently there is no information on the the breaking change about injection token generation which changed in version 8. Every few days there is a question related to this topic in the NestJS Discord why this and that no longer works:

Example: My code no longer works:

My provider:

{
  provide: SomeProvider,
  useClass: SomeClass,
}

My service:

...
constructor(private readonly someProvider: SomeProvider)
...

The error is Error: Nest can't resolve dependencies of the .....

It comes down to people not knowing about the change that injection tokens are no longer the class names.

Expected behavior

Update the v8 migration guide to include a note about this change and an explanation why the old way worked and the new doesn't.

Minimal reproduction of the problem with instructions

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

Better informed developers

Environment

For Tooling issues:

  • Node version: XX
  • Platform:

Others:

I know it was not ment for "consumers" to know about this and they should have used the @Inject decorator but juding by the amount of questions related to this it might not be common knowledge.

Flusinerd avatar Feb 19 '23 20:02 Flusinerd

You could add a warning, but I'm not sure if this is the best idea. 🤔 Because in the documentation if I'm not mistaken the use of string class names as injection tokens was never really documented.

Tony133 avatar Feb 20 '23 10:02 Tony133

@Flusinerd not sure what do you meant with that example because it does works in v8. It won't work if you have @Inject("SomeProvider")

I don't think this should be listed in the docs because it was never documented in first place. Also, it was mentioned in the PR linked in the migration guide, which can be seem as a changelog.

micalevisk avatar Jun 27 '24 23:06 micalevisk