{"action":"opened","issue":{"url":"https://api.github.com/repos/emurano/Ding/issues/1","repository_url":"https://api.github.com/repos/emurano/Ding","labels_url":"https://api.github.com/repos/emurano/Ding/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/emurano/Ding/issues/1/comments","events_url":"https://api.github.com/repos/emurano/Ding/issues/1/events","html_url":"https://github.com/emurano/Ding/issues/1","id":193671644,"number":1,"title":"Allow @Value annotations to work on setter methods","user":{"login":"emurano","id":2396940,"avatar_url":"https://avatars.githubusercontent.com/u/2396940?v=3","gravatar_id":"","url":"https://api.github.com/users/emurano","html_url":"https://github.com/emurano","followers_url":"https://api.github.com/users/emurano/followers","following_url":"https://api.github.com/users/emurano/following{/other_user}","gists_url":"https://api.github.com/users/emurano/gists{/gist_id}","starred_url":"https://api.github.com/users/emurano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emurano/subscriptions","organizations_url":"https://api.github.com/users/emurano/orgs","repos_url":"https://api.github.com/users/emurano/repos","events_url":"https://api.github.com/users/emurano/events{/privacy}","received_events_url":"https://api.github.com/users/emurano/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-06T03:08:14Z","updated_at":"2016-12-06T03:08:14Z","closed_at":null,"body":"Currently if you want to inject a property value into your bean's member variable with the @Value annotation,  you need to put the @Value annotation on the private member variable's declaration:\r\n\r\n`class MyBean {\r\n\t/**\r\n\t * @Value(value=${app.properties.name}\r\n\t */\r\n\tprotected $name;\r\n}`\r\n\r\nIf you want Ding to inject the value using a setter method you create the setter method with a name that matches the setter format set<property name>, with <property name>'s first character being uppercase:\r\n\r\n`class MyBean {\r\n\t/**\r\n\t * @Value(value=${app.properties.name}\r\n\t */\r\n\tprotected $name;\r\n\t\r\n\tpublic function setName($name) {\r\n\t\t$this->name = $name;\r\n\t}\r\n}`\r\n\r\nI would like it if Ding could inject property values if the @Value annotation is on the setter method and not on the member variable declaration, like this:\r\n\r\n`class MyBean {\r\n\r\n\tprotected $name;\r\n\t\r\n\t/**\r\n\t * @Value(value=${app.properties.name}\r\n\t */\r\n\tpublic function setName($name) {\r\n\t\t$this->name = $name;\r\n\t}\r\n}`\r\n\r\nThere are two justifications for this:\r\n\r\n1. Consistency: When you inject resources using setter methods you can specify the @Resource annotation on the setter instead of the member variable. Because of this I made the assumption that you could inject values using @Value on the setter method and burned some time figuring out what was wrong.\r\n\r\n2. Flexibility: There will be times when I don't want to save the value to a property. I might want to use the value as the input data for a more complex process. E.g. if I inject a comma separated string I might want to do something like this:\r\n\r\n`class MyBean {\r\n\r\n\tprotected $nameList = [];\r\n\t\r\n\t/**\r\n\t * @Value(value=${app.properties.names}\r\n\t */\r\n\tpublic function setNamesFromCsv($names) {\r\n\t\t$this->nameList = explode(',', $names);\r\n\t}\r\n}`\r\n\r\n"}}
{"actor":{"display_login":"emurano"}}