Skip to content

fix: avoiding metadataStorage from DI#335

Merged
vlapo merged 1 commit into
typestack:masterfrom
satanTime:master
Mar 24, 2020
Merged

fix: avoiding metadataStorage from DI#335
vlapo merged 1 commit into
typestack:masterfrom
satanTime:master

Conversation

@satanTime

@satanTime satanTime commented Mar 18, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown

@satanTime

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

@exwyezed

Copy link
Copy Markdown

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

TrejGun commented Dec 27, 2019

Copy link
Copy Markdown

@vlapo can this be merged?

@rightjelkin

Copy link
Copy Markdown

LGTM

2 similar comments
@Chessman97

Copy link
Copy Markdown

LGTM

@DenisKn

DenisKn commented Dec 28, 2019

Copy link
Copy Markdown

LGTM

@satanTime

satanTime commented Feb 19, 2020

Copy link
Copy Markdown
Contributor Author

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

@satanTime

Copy link
Copy Markdown
Contributor Author

Hi @vlapo, could you review?

@TrejGun

TrejGun commented Feb 23, 2020

Copy link
Copy Markdown

@vlapo please

@satanTime

Copy link
Copy Markdown
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

vlapo commented Mar 24, 2020

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor Author

Thanks!

@vlapo

vlapo commented Mar 24, 2020

Copy link
Copy Markdown
Contributor

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

@TrejGun

TrejGun commented Mar 25, 2020

Copy link
Copy Markdown

thanks!

@nolazybits

nolazybits commented May 12, 2020

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Aug 3, 2020

Copy link
Copy Markdown

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