-
Notifications
You must be signed in to change notification settings - Fork 724
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
onDeactivation throws 'TypeError: Cannot convert undefined or null to object' #1462
Comments
I've got the same error message but with a different scenario. I accidentally bound "undefined" on the container: import 'reflect-metadata';
import { Container } from 'inversify';
const container = new Container();
container.bind('Test').toConstantValue(undefined);
console.log(container.get('Test')); // undefined
container.unbindAll(); // Error: Cannot convert undefined or null to object This issue can be resolved by removing improper binding. |
I would hazard to say this issue is already solved. enum Identifier {
Blade = 'Blade',
}
interface Blade {
sharpness: number;
}
class BladeImpl implements Blade {
constructor(@optional() @unmanaged() public sharpness: number = 5) {}
}
const container: Container = new Container();
container.bind<Blade>(Identifier.Blade).to(BladeImpl).inSingletonScope();
container.onActivation(Identifier.Blade, () => {
console.log('blade instance Activation!');
});
container.onDeactivation(
Identifier.Blade,
(_blade: Blade): void | Promise<void> => {
console.log('blade instance deactivation!');
},
);
container.get<Blade>(Identifier.Blade);
container.unbind(Identifier.Blade); is currently working with the latest Regarding the runtime error, it should be solved since #1628. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If container has both onActivation handler and onDeactivation, onDeactivation throws error.
Expected Behavior
working without error
Current Behavior
this error pops out
Possible Solution
Steps to Reproduce (for bugs)
https://github.com/inversify/InversifyJS/blob/master/wiki/container_api.md#containeronactivationtserviceidentifier-interfacesserviceidentifiert-onactivation-interfacesbindingactivationt-void
https://github.com/inversify/InversifyJS/blob/master/wiki/container_api.md#ondeactivationtserviceidentifier-interfacesserviceidentifiert-ondeactivation-interfacesbindingdeactivationt-void
https://github.com/inversify/InversifyJS/blob/master/wiki/deactivation_handler.md#deactivation-handler
Context
Your Environment
Stack trace
The text was updated successfully, but these errors were encountered: