{"action":"created","issue":{"url":"https://api.github.com/repos/snd/hinoki/issues/4","labels_url":"https://api.github.com/repos/snd/hinoki/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/snd/hinoki/issues/4/comments","events_url":"https://api.github.com/repos/snd/hinoki/issues/4/events","html_url":"https://github.com/snd/hinoki/issues/4","id":72206688,"number":4,"title":"make hinoki figure out lifetimes automatically by looking at the dependencies","user":{"login":"snd","id":32397,"avatar_url":"https://avatars.githubusercontent.com/u/32397?v=3","gravatar_id":"","url":"https://api.github.com/users/snd","html_url":"https://github.com/snd","followers_url":"https://api.github.com/users/snd/followers","following_url":"https://api.github.com/users/snd/following{/other_user}","gists_url":"https://api.github.com/users/snd/gists{/gist_id}","starred_url":"https://api.github.com/users/snd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snd/subscriptions","organizations_url":"https://api.github.com/users/snd/orgs","repos_url":"https://api.github.com/users/snd/repos","events_url":"https://api.github.com/users/snd/events{/privacy}","received_events_url":"https://api.github.com/users/snd/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/snd/hinoki/labels/idea","name":"idea","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-30T16:10:17Z","updated_at":"2015-05-05T14:21:36Z","closed_at":null,"body":"currently the user has to manually divide/organize factories by their lifetime (the folders `application`, `request`, `middleware` in the case of [fragments](https://github.com/snd/fragments)) and move factories manually between lifetimes/files if their lifetime changes.\r\n\r\nit would be really nice if hinoki would figure this out for us !\r\n\r\nthat is possible:\r\nif a fragment directly or indirectly depends on `params` or `next` it is in the **middleware** lifetime.\r\nif a fragment directly or indirectly depends on `req` or `res` it is in the **request** lifetime.\r\notherwise it is in the **application** lifetime.\r\n\r\nis this a good idea overall ?\r\nare there any disadvantages/showstoppers when compared to the manual solution ?\r\ndoes this break other usage patterns of hinoki than our own ?\r\nhow to implement this ?\r\nhow to transition to this ?\r\n\r\n**needs a lot more thought !**\r\n\r\n### possible implementation\r\n\r\nfactories/sources are currently complected with state/values in containers.\r\n\r\ndecomplect: have hinoki consume an array of sources (which are either \"objects containing factories\" or \"factory factories\") as well as an array of lifetimes.\r\n\r\nlifetimes will be what `lifetime.values` currently is.\r\nlifetimes are simply objects of values. \r\nlifetimes manage state.\r\n\r\n**a value will then be cached in the last lifetime that contains values it directly or indirectly depends on. et voila !**\r\n\r\n``` javascript\r\nhinoki(sourceS, lifetimeS, nameS);\r\n```\r\n\r\n### notes\r\n\r\ncare has to be taken with fragments that should only exist during a specific lifetime but don't depend on values in that lifetime.\r\n`k` in fragments is an example.\r\na solution is to use `params` or `next` as an unused \"marker-dependency\" to force it into the **middleware** lifetime.\r\n\r\n\r\nneed a solution for `promisesAwaitingResolution`.\r\npreviously in lifetimes. where now ?\r\nas `__promises` in new lifetimes ?\r\n\r\n\r\nwe could also detect lifetimes ahead of time by looking at the dependencies\r\nand then either add them as metadata to the factories `$lifetime` or filter factories into the specific lifetimes and use the old lifetime system.\r\n\r\n\r\nlifetimes only control/influence where and how long the value will be cached."},"comment":{"url":"https://api.github.com/repos/snd/hinoki/issues/comments/99092888","html_url":"https://github.com/snd/hinoki/issues/4#issuecomment-99092888","issue_url":"https://api.github.com/repos/snd/hinoki/issues/4","id":99092888,"user":{"login":"snd","id":32397,"avatar_url":"https://avatars.githubusercontent.com/u/32397?v=3","gravatar_id":"","url":"https://api.github.com/users/snd","html_url":"https://github.com/snd","followers_url":"https://api.github.com/users/snd/followers","following_url":"https://api.github.com/users/snd/following{/other_user}","gists_url":"https://api.github.com/users/snd/gists{/gist_id}","starred_url":"https://api.github.com/users/snd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snd/subscriptions","organizations_url":"https://api.github.com/users/snd/orgs","repos_url":"https://api.github.com/users/snd/repos","events_url":"https://api.github.com/users/snd/events{/privacy}","received_events_url":"https://api.github.com/users/snd/received_events","type":"User","site_admin":false},"created_at":"2015-05-05T14:21:36Z","updated_at":"2015-05-05T14:21:36Z","body":":+1: "}}