Skip to content

docs: add minimal example for usage with inversify #607

Open

Description

@nolazybits

Description

Hello everyone.

Using the last version 0.12.2 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)
Just wondering If some more changes need to be done
https://github.com/typestack/class-validator/search?q=getFromContainer&unscoped_q=getFromContainer

Just wondering If some more changes need to be done
https://github.com/typestack/class-validator/search?q=getFromContainer&unscoped_q=getFromContainer

Any ideas?

Thanks for all the hard work btw 👍

Environment

  • nodejs: 12
  • framework/library: nodebrick

class-validator version: 0.12.2

Activity

  1. nolazybits commented on May 12, 2020

    @nolazybits
    ContributorAuthor

    So I had to actually remove the use of the DI container all together it seems to have it working
    Is that correct?

    Before

            useContainer(
                new InversifyContainerWrapper(NodebrickCore._ContainerDI),
                {
                    fallbackOnErrors: false,
                    fallback: false,
                });
    

    I removed the ☝️ code and it works. Is that the correct approach?

    Cheers :)

  2. satanTime commented on May 12, 2020

    @satanTime
    Contributor

    Without useContainer I think it doesn't solve dependencies and they are undefined, please check them in constructors of your validators.
    And might you share code of CustomConstraint?

  3. harindaka commented on Nov 28, 2020

    @harindaka

    @satanTime I'm facing this problem too using class-validator with inversify. I do not have a CustomConstraint class defined anywhere in my code. What could be the reason? Are there any instructions for using class-validator with inversify or a code sample?

  4. satanTime commented on Nov 28, 2020

    @satanTime
    Contributor

    Hi @harindaka,

    Is there a chance to create an example with min code to reproduce the issue?

  5. harindaka commented on Nov 28, 2020

    @harindaka

    @satanTime ok after some googling, I found that it is necessary to use an adaptor for third party DI containers such as inversify to work. Obviously this must be the reason for me since I was not aware of that. It's not super obvious to someone who's only using class validator and not routing controllers. Maybe update the documentation for class-validator to link to that?

  6. satanTime commented on Nov 28, 2020

    @satanTime
    Contributor

    @harindaka, yep, makes sense, might you create a PR? I think you know better how to describe it.

  7. harindaka commented on Nov 28, 2020

    @harindaka
  8. changed the title [-]missing binding CustomConstraint[/-] [+]docs: add minimal example for usage with inversify[/+] on Jan 11, 2021
  9. added
    type: feature
    on Jan 11, 2021
  10. dreamerblue commented on Feb 28, 2021

    @dreamerblue

    Same issue. Any progress for supporting inversify?

  11. afraz-khan commented on Nov 23, 2021

    @afraz-khan

    any official documentation piece for this?

  12. ttruongatl commented on Jan 18, 2022

    @ttruongatl

    The following could be a solution!

    // InversifyContainerAdapter.ts
    
    import { Container } from "inversify";
    
    export class InversifyContainerAdapter extends Container {
      public get<T>(serviceIdentifier: any): T {
        const id = serviceIdentifier;
        try{
         return super.get(id);
        }catch(e){
          this.bind(serviceIdentifier).to(serviceIdentifier).inSingletonScope();
        }
        return super.get(id);
      }
    }
    
    // App.ts
    
    import { Container } from "inversify";
    import { useContainer } from "class-validator";
    import {InversifyContainerAdapter} from "./InversifyContainerAdapter";
    
    const container = new InversifyContainerAdapter();
    useContainer(container);
    
    
  13. LimbersMay commented on Aug 10, 2023

    @LimbersMay

    @ttruongatl I tried your solution but now I get:

    I am using routing-controllers, inversify and class-validator.

    Error: Missing required @injectable annotation in: Validator. node-app | at getTargets (/usr/src/app/node_modules/inversify/src/planning/reflection_utils.ts:32:11) node-app | at getDependencies (/usr/src/app/node_modules/inversify/src/planning/reflection_utils.ts:14:10) node-app | at /usr/src/app/node_modules/inversify/src/planning/planner.ts:179:43 node-app | at Array.forEach (<anonymous>) node-app | at _createSubRequests (/usr/src/app/node_modules/inversify/src/planning/planner.ts:164:18) node-app | at plan (/usr/src/app/node_modules/inversify/src/planning/planner.ts:240:5) node-app | at /usr/src/app/node_modules/inversify/src/container/container.ts:623:25 node-app | at InversifyContainerAdapter.Container._get (/usr/src/app/node_modules/inversify/src/container/container.ts:574:37) node-app | at InversifyContainerAdapter.Container._getButThrowIfAsync (/usr/src/app/node_modules/inversify/src/container/container.ts:580:25) node-app | at InversifyContainerAdapter.Container.get (/usr/src/app/node_modules/inversify/src/container/container.ts:325:17)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions