{"action":"created","issue":{"url":"https://api.github.com/repos/inversify/InversifyJS/issues/445","repository_url":"https://api.github.com/repos/inversify/InversifyJS","labels_url":"https://api.github.com/repos/inversify/InversifyJS/issues/445/labels{/name}","comments_url":"https://api.github.com/repos/inversify/InversifyJS/issues/445/comments","events_url":"https://api.github.com/repos/inversify/InversifyJS/issues/445/events","html_url":"https://github.com/inversify/InversifyJS/issues/445","id":195316477,"number":445,"title":"how to call the initialization method?","user":{"login":"acopalipsis","id":9849922,"avatar_url":"https://avatars.githubusercontent.com/u/9849922?v=3","gravatar_id":"","url":"https://api.github.com/users/acopalipsis","html_url":"https://github.com/acopalipsis","followers_url":"https://api.github.com/users/acopalipsis/followers","following_url":"https://api.github.com/users/acopalipsis/following{/other_user}","gists_url":"https://api.github.com/users/acopalipsis/gists{/gist_id}","starred_url":"https://api.github.com/users/acopalipsis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acopalipsis/subscriptions","organizations_url":"https://api.github.com/users/acopalipsis/orgs","repos_url":"https://api.github.com/users/acopalipsis/repos","events_url":"https://api.github.com/users/acopalipsis/events{/privacy}","received_events_url":"https://api.github.com/users/acopalipsis/received_events","type":"User","site_admin":false},"labels":[{"id":196905384,"url":"https://api.github.com/repos/inversify/InversifyJS/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-13T17:26:54Z","updated_at":"2016-12-13T18:03:02Z","closed_at":"2016-12-13T17:48:06Z","body":"was class - \r\n\r\n```\r\nclass A {\r\n    constructor(a: number, b: number){\r\n        this.c = a + b;\r\n    }\r\n}\r\n```\r\n\r\nbecame class - \r\n\r\n```\r\n@injectable()\r\nclass A {\r\n    @inject()\r\n    public a: number;\r\n    @inject()\r\n    public b: number;\r\n    \r\n    \r\n    public c: number;\r\n    \r\n    constructor(){}\r\n    \r\n    init(){\r\n        // ???\r\n        \r\n        this.c = a + b;\r\n    }\r\n}\r\n```\r\n\r\nNow, how to initialize?"},"comment":{"url":"https://api.github.com/repos/inversify/InversifyJS/issues/comments/266813764","html_url":"https://github.com/inversify/InversifyJS/issues/445#issuecomment-266813764","issue_url":"https://api.github.com/repos/inversify/InversifyJS/issues/445","id":266813764,"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-13T18:03:02Z","updated_at":"2016-12-13T18:03:02Z","body":"In you example you used property injection. That also works:\r\n```ts\r\n@injectable()\r\nclass A {\r\n\r\n    @inject(\"A\")\r\n    public a: number;\r\n\r\n    @inject(\"B\")\r\n    public b: number;\r\n    \r\n    \r\n    public c: number;\r\n    \r\n    // constructor(){} no need for default constructor\r\n    \r\n    init(){\r\n        this.c = this.a + this.b;\r\n    }\r\n}\r\n```\r\n\r\nIf you work with primitive values or classes (not interfaces) @inject annotations are not needed:\r\n\r\n```ts\r\n@injectable()\r\nclass A {\r\n    public c: number;\r\n    constructor(a: number, b: number) {\r\n         this.c = a + b;\r\n    }\r\n}\r\n```\r\n\r\nThe problem is that a and b are the same type so the same value will be injected unless you declare a constraint:\r\n\r\n```ts\r\nkernel.bind<number>(\"Number\").toConstantValue(5).when((request: interfaces.Request) => {\r\n    return request.target.name.equals(\"a\");\r\n});\r\n\r\nkernel.bind<number>(\"Number\").toConstantValue(5).when((request: interfaces.Request) => {\r\n    return request.target.name.equals(\"b\");\r\n});\r\n```\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"remojansen"}}