{"action":"created","issue":{"url":"https://api.github.com/repos/inversify/InversifyJS/issues/275","repository_url":"https://api.github.com/repos/inversify/InversifyJS","labels_url":"https://api.github.com/repos/inversify/InversifyJS/issues/275/labels{/name}","comments_url":"https://api.github.com/repos/inversify/InversifyJS/issues/275/comments","events_url":"https://api.github.com/repos/inversify/InversifyJS/issues/275/events","html_url":"https://github.com/inversify/InversifyJS/issues/275","id":162333415,"number":275,"title":"Property injection decorator without kernel","user":{"login":"rashtao","id":1259903,"avatar_url":"https://avatars.githubusercontent.com/u/1259903?v=3","gravatar_id":"","url":"https://api.github.com/users/rashtao","html_url":"https://github.com/rashtao","followers_url":"https://api.github.com/users/rashtao/followers","following_url":"https://api.github.com/users/rashtao/following{/other_user}","gists_url":"https://api.github.com/users/rashtao/gists{/gist_id}","starred_url":"https://api.github.com/users/rashtao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rashtao/subscriptions","organizations_url":"https://api.github.com/users/rashtao/orgs","repos_url":"https://api.github.com/users/rashtao/repos","events_url":"https://api.github.com/users/rashtao/events{/privacy}","received_events_url":"https://api.github.com/users/rashtao/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/inversify/InversifyJS/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-26T15:49:54Z","updated_at":"2016-06-27T12:22:57Z","closed_at":null,"body":"All the examples about `Property injection`  (documented [here](https://github.com/inversify/InversifyJS/blob/master/wiki/property_injection.md)) use an instance of the `Kernel` to create the decorator:\r\n\r\n```js\r\nlet kernel = new Kernel();\r\nlet inject = makePropertyInjectDecorator(kernel);\r\n// ...\r\n// ... use @inject for Property injection\r\n// ...\r\n```\r\n\r\nBut this introduces a dependency on one specific instance of `kernel`, so breaking the IoC principle.\r\n\r\nIs there a way to avoid it? \r\n\r\nAn example to clarify: I am creating an HTTP server framework and want to leave to the user the responsibility to:\r\n- create the kernel \r\n- bind the framework modules \r\n- bind configurations \r\n\r\nSo the framework library contains:\r\n\r\n```js\r\n@inject(\"HttpConfig\")\r\nclass HttpServer{\r\n     // use HttpConfig\r\n}\r\n```\r\n\r\nwhere `HttpConfig` is injected in the constructor. The user can use it in this way:\r\n\r\n```js\r\nimport {HttpServer} from \"framework\";\r\nimport {Kernel} from \"inversify\";\r\n\r\nlet kernel = new Kernel();\r\nkernel.bind(\"HttpConfig\").toValue({\"port\": 8080});\r\nkernel.bind(\"HttpServer\").to(HttpServer);\r\n```\r\n\r\nHow can I modify the sample code in order to use `Property injection`? "},"comment":{"url":"https://api.github.com/repos/inversify/InversifyJS/issues/comments/228730471","html_url":"https://github.com/inversify/InversifyJS/issues/275#issuecomment-228730471","issue_url":"https://api.github.com/repos/inversify/InversifyJS/issues/275","id":228730471,"user":{"login":"rashtao","id":1259903,"avatar_url":"https://avatars.githubusercontent.com/u/1259903?v=3","gravatar_id":"","url":"https://api.github.com/users/rashtao","html_url":"https://github.com/rashtao","followers_url":"https://api.github.com/users/rashtao/followers","following_url":"https://api.github.com/users/rashtao/following{/other_user}","gists_url":"https://api.github.com/users/rashtao/gists{/gist_id}","starred_url":"https://api.github.com/users/rashtao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rashtao/subscriptions","organizations_url":"https://api.github.com/users/rashtao/orgs","repos_url":"https://api.github.com/users/rashtao/repos","events_url":"https://api.github.com/users/rashtao/events{/privacy}","received_events_url":"https://api.github.com/users/rashtao/received_events","type":"User","site_admin":false},"created_at":"2016-06-27T12:22:56Z","updated_at":"2016-06-27T12:22:56Z","body":"Thanks for the response. I agree that using constructor injection makes everything better, independently from the library/framework/language. For my implementation I am fine with using it.\r\n\r\nAbout the approach that you propose, I think it is almost like using the kernel as `Service Locator` registry. But it would be another design pattern, sometimes considered an anti-pattern!\r\n\r\nMaybe you could explicitly clarify in the documentation/examples that setter injection is achieved using the kernel as `Service Locator` registry.\r\n\r\nFeel free to close this issue and congrats for your work and help! \r\n"}}
{"actor":{"display_login":"rashtao"}}