{"action":"created","issue":{"url":"https://api.github.com/repos/inversify/InversifyJS/issues/457","repository_url":"https://api.github.com/repos/inversify/InversifyJS","labels_url":"https://api.github.com/repos/inversify/InversifyJS/issues/457/labels{/name}","comments_url":"https://api.github.com/repos/inversify/InversifyJS/issues/457/comments","events_url":"https://api.github.com/repos/inversify/InversifyJS/issues/457/events","html_url":"https://github.com/inversify/InversifyJS/issues/457","id":197460323,"number":457,"title":"Binding parameters sanity validation","user":{"login":"IdeaHunter","id":10799080,"avatar_url":"https://avatars.githubusercontent.com/u/10799080?v=3","gravatar_id":"","url":"https://api.github.com/users/IdeaHunter","html_url":"https://github.com/IdeaHunter","followers_url":"https://api.github.com/users/IdeaHunter/followers","following_url":"https://api.github.com/users/IdeaHunter/following{/other_user}","gists_url":"https://api.github.com/users/IdeaHunter/gists{/gist_id}","starred_url":"https://api.github.com/users/IdeaHunter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IdeaHunter/subscriptions","organizations_url":"https://api.github.com/users/IdeaHunter/orgs","repos_url":"https://api.github.com/users/IdeaHunter/repos","events_url":"https://api.github.com/users/IdeaHunter/events{/privacy}","received_events_url":"https://api.github.com/users/IdeaHunter/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-12-24T11:58:24Z","updated_at":"2016-12-28T16:39:40Z","closed_at":null,"body":"I occasionally passed wrong parameter type (string) for `toSelf` binding and got error with no message only after trying to instantiate it\r\n\r\n## Expected Behavior\r\nThrow an error/emit compilation error when calling `toSelf`\r\n\r\n## Current Behavior\r\nAn error with no message (see callstacks below)\r\n\r\n## Possible Solution\r\nAdd some soft of foolproofness for input parameters with meaningful error message - or maybe find a way to restrict things at compilation level - since there also issue with _de facto_ argument **type**\r\n\r\n## Steps to Reproduce (for bugs)\r\n```js\r\nimport \"reflect-metadata\"\r\nimport { Container } from 'inversify'\r\nlet container = new Container()\r\ncontainer.bind('testId').toSelf()\r\nlet service = container.get('testId')\r\n```\r\n## Context\r\nIm using helper function to dynamically create child container with different set of dependencies to instantiate class with it and also to abstract out of inversify itself\r\n```js\r\nfunction create<T>(ctx: interfaces.Context, type: interfaces.ServiceIdentifier<any>, args: { [name: string]: any }): IPromise<T> {\r\n    if (!args)\r\n        return ctx.container.get(type)\r\n\r\n    let innerKernel = new Container()\r\n    innerKernel.parent = ctx.container\r\n    _.each(args, (val, key) => {\r\n        if (typeof val === 'function') {\r\n            innerKernel.bind(key).to(val)\r\n        } else {\r\n            innerKernel.bind(key).toConstantValue(val)\r\n        }\r\n    })\r\n    // this line lead me to an error - it got removed right after the bug appear\r\n    innerKernel.bind(type).toSelf()\r\n    return innerKernel.get(type)\r\n}\r\n\r\nchildKernel.bind('create').toDynamicValue(ctx => function createSubContainerDi(type, args) {\r\n    if (type === 'create')\r\n        return (type, args) => create(ctx, type, args)\r\n    else\r\n        return create(ctx, type, args)\r\n})\r\n```\r\n\r\n## Your Environment\r\n* Version used: 3.0.0-rc.2, (reflect-metadata: 0.1.9) \r\n* Environment name and version: node v7.2.1\r\n* Operating System and version (desktop or mobile):  Debian GNU/Linux testing (stretch), desktop\r\n* Link to your project: its private\r\n\r\n# Stack trace\r\n1) Rethrown stacktrace\r\n```\r\nError,\r\n    at _createSubRequests (/home/igor/psb/node_modules/inversify/lib/planning/planner.js:106:19)\r\n    at Object.plan (/home/igor/psb/node_modules/inversify/lib/planning/planner.js:125:5)\r\n    at /home/igor/psb/node_modules/inversify/lib/container/container.js:191:37\r\n    at Container._get (/home/igor/psb/node_modules/inversify/lib/container/container.js:184:44)\r\n    at Container.get (/home/igor/psb/node_modules/inversify/lib/container/container.js:149:21)\r\n```\r\n2) Full stack trace\r\n```\r\nTypeError\r\n    at Object.getMetadata (/home/igor/psb/node_modules/reflect-metadata/Reflect.ts:704:38)\r\n    at getTargets (/home/igor/psb/node_modules/inversify/lib/planning/reflection_utils.js:21:38)\r\n    at Object.getDependencies (/home/igor/psb/node_modules/inversify/lib/planning/reflection_utils.js:9:19)\r\n    at /home/igor/psb/node_modules/inversify/lib/planning/planner.js:93:55\r\n    at Array.forEach (native)\r\n    at _createSubRequests (/home/igor/psb/node_modules/inversify/lib/planning/planner.js:84:24)\r\n    at Object.plan (/home/igor/psb/node_modules/inversify/lib/planning/planner.js:116:5)\r\n    at /home/igor/psb/node_modules/inversify/lib/container/container.js:191:37\r\n    at Container._get (/home/igor/psb/node_modules/inversify/lib/container/container.js:184:44)\r\n    at Container.get (/home/igor/psb/node_modules/inversify/lib/container/container.js:149:21)\r\n```"},"comment":{"url":"https://api.github.com/repos/inversify/InversifyJS/issues/comments/269503014","html_url":"https://github.com/inversify/InversifyJS/issues/457#issuecomment-269503014","issue_url":"https://api.github.com/repos/inversify/InversifyJS/issues/457","id":269503014,"user":{"login":"remojansen","id":10656223,"avatar_url":"https://avatars.githubusercontent.com/u/10656223?v=3","gravatar_id":"","url":"https://api.github.com/users/remojansen","html_url":"https://github.com/remojansen","followers_url":"https://api.github.com/users/remojansen/followers","following_url":"https://api.github.com/users/remojansen/following{/other_user}","gists_url":"https://api.github.com/users/remojansen/gists{/gist_id}","starred_url":"https://api.github.com/users/remojansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remojansen/subscriptions","organizations_url":"https://api.github.com/users/remojansen/orgs","repos_url":"https://api.github.com/users/remojansen/repos","events_url":"https://api.github.com/users/remojansen/events{/privacy}","received_events_url":"https://api.github.com/users/remojansen/received_events","type":"User","site_admin":false},"created_at":"2016-12-28T16:39:40Z","updated_at":"2016-12-28T16:39:40Z","body":"There is no way to catch this at compilation time but I have added a validation check that will be included in the release.\r\n\r\nIt will throw the following:\r\n\r\n> The toSelf function can only be applied when a constructor is used as service identifier"}}
{"actor":{"display_login":"remojansen"}}