Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoiding metadataStorage from DI #335

Merged
merged 1 commit into from
Mar 24, 2020
Merged

fix: avoiding metadataStorage from DI #335

merged 1 commit into from
Mar 24, 2020

Conversation

satanTime
Copy link
Contributor

@satanTime satanTime commented Mar 18, 2019

We can’t use MetadataStorage with DI because decorators are parsed before the very first call of useContainer, and therefore after the very fist call of useContainer the current MetadataStorage in the default container has been replaced with a brand new one without any metadata inside.

Possible runtime fix is to disable MetadataStorage in the typedi container:

import {MetadataStorage, useContainer} from 'class-validator';
import {Container} from 'typedi';

useContainer(Container, {
    fallback: true,
});
Container.set(MetadataStorage, null);

Closes #328.
Closes #261.
Closes #132.

@MardariG
Copy link

@satanTime

forked and merged your branch, and published it on npm as @mardari/class-validator.
Is working well, Thank you!

@alfonmga
Copy link

OH MY GOD, thank you guys!!!! I have been stuck at this issue for 10 hours

Here's the damned error message so others can find this issue on Google quickly:
(node:61756) UnhandledPromiseRejectionWarning: Error: No matching bindings found for serviceIdentifier: MetadataStorage

@MardariG you npm package @mardari/class-validator still working fine at this moment :)

@TrejGun
Copy link

TrejGun commented Dec 27, 2019

@vlapo can this be merged?

@rightjelkin
Copy link

LGTM

2 similar comments
@Chessman97
Copy link

LGTM

@DenisKn
Copy link

DenisKn commented Dec 28, 2019

LGTM

@satanTime
Copy link
Contributor Author

satanTime commented Feb 19, 2020

Hi guys I've updated the description with a possible fix until the PR has been merged.

@satanTime
Copy link
Contributor Author

Hi @vlapo, could you review?

@TrejGun
Copy link

TrejGun commented Feb 23, 2020

@vlapo please

@satanTime
Copy link
Contributor Author

Hi @vlapo, might you provide any feedback about the issue?

We can’t use MetadataStorage with DI because decorators are parsed before the very first call of useContainer, and therefore after the very fist call of useContainer the current MetadataStorage in the default container has been replaced with a brand new one without any metadata inside.

Closes #328.
Closes #261.
Closes #132.
@vlapo
Copy link
Contributor

vlapo commented Mar 24, 2020

@satanTime I thank you for your determination and perseverance. This looks good for me. I will merge it and publish pre-release for testing.

@vlapo vlapo changed the title #328: avoiding metadataStorage from DI fix: avoiding metadataStorage from DI Mar 24, 2020
@vlapo vlapo merged commit b57fef4 into typestack:master Mar 24, 2020
@satanTime
Copy link
Contributor Author

Thanks!

@vlapo
Copy link
Contributor

vlapo commented Mar 24, 2020

Happy testing https://www.npmjs.com/package/class-validator/v/0.12.0-rc.0. Please give me a feedback.

@TrejGun
Copy link

TrejGun commented Mar 25, 2020

thanks!

@nolazybits
Copy link
Contributor

nolazybits commented May 12, 2020

after updating, I receive

Error: No matching bindings found for serviceIdentifier: CustomConstraint
    at _validateActiveBindingCount (/home/nodebrick/application/node_modules/inversify/lib/planning/planner.js:62:23)
    at _getActiveBindings (/home/nodebrick/application/node_modules/inversify/lib/planning/planner.js:48:5)
    at _createSubRequests (/home/nodebrick/application/node_modules/inversify/lib/planning/planner.js:85:26)
    at Object.plan (/home/nodebrick/application/node_modules/inversify/lib/planning/planner.js:136:9)
    at /home/nodebrick/application/node_modules/inversify/lib/container/container.js:317:37
    at Container._get (/home/nodebrick/application/node_modules/inversify/lib/container/container.js:310:44)
    at Container.get (/home/nodebrick/application/node_modules/inversify/lib/container/container.js:230:21)
    at InversifyContainerWrapper.get (/home/nodebrick/application/packages/nodebrick-core/src/di/InversifyContainerWrapper.ts:23:45)
    at getFromContainer (/home/nodebrick/application/node_modules/src/container.ts:53:44)
    at ConstraintMetadata.get [as instance] (/home/nodebrick/application/node_modules/src/metadata/ConstraintMetadata.ts:46:16)

Opened a ticket here #607
Thanks

@github-actions
Copy link

github-actions bot commented Aug 3, 2020

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
9 participants