inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.02k stars 712 forks source link

regression: inversify 6 no longer allows binding null values #1519

Open simhnna opened 1 year ago

simhnna commented 1 year ago

Used to work in inversify 5

import { Container } from "inversify";

const container = new Container();
const s = Symbol('foo');
container.bind(s).toConstantValue(null);

console.log(container.get(s));

Produces:

/project/node_modules/inversify/lib/utils/binding_utils.js:62
        throw new Error(ERROR_MSGS.INVALID_BINDING_TYPE + " " + serviceIdentifierAsString);
              ^

Error: Invalid binding type: Symbol(foo)
    at ensureFullyBound (/project/node_modules/inversify/lib/utils/binding_utils.js:62:15)
    at _getResolvedFromBinding (/project/node_modules/inversify/lib/resolution/resolver.js:99:42)
    at /project/node_modules/inversify/lib/resolution/resolver.js:127:22
    at _resolveInScope (/project/node_modules/inversify/lib/resolution/resolver.js:121:14)
    at _resolveBinding (/project/node_modules/inversify/lib/resolution/resolver.js:126:12)
    at /project/node_modules/inversify/lib/resolution/resolver.js:88:20
    at resolve (/project/node_modules/inversify/lib/resolution/resolver.js:225:12)
    at /project/node_modules/inversify/lib/container/container.js:622:49
    at Container._get (/project/node_modules/inversify/lib/container/container.js:590:38)
    at Container._getButThrowIfAsync (/project/node_modules/inversify/lib/container/container.js:593:27)
weyert commented 9 months ago

Have you found a solution for this?

simhnna commented 9 months ago

You can wrap primitives { value: null }

It's currently no longer a high priority for my projects. If I have time I might try creating a merge request that allows binding null values but understanding the code of inversofy isn't very easy...

Jameskmonger commented 7 months ago

Added to milestone 6.0.3, we will aim to resolve this regression as a priority. cc @PodaruDragos