{"action":"created","issue":{"url":"https://api.github.com/repos/koajs/koa/issues/473","labels_url":"https://api.github.com/repos/koajs/koa/issues/473/labels{/name}","comments_url":"https://api.github.com/repos/koajs/koa/issues/473/comments","events_url":"https://api.github.com/repos/koajs/koa/issues/473/events","html_url":"https://github.com/koajs/koa/issues/473","id":102932796,"number":473,"title":"API for extending context","user":{"login":"cesarandreu","id":656870,"avatar_url":"https://avatars.githubusercontent.com/u/656870?v=3","gravatar_id":"","url":"https://api.github.com/users/cesarandreu","html_url":"https://github.com/cesarandreu","followers_url":"https://api.github.com/users/cesarandreu/followers","following_url":"https://api.github.com/users/cesarandreu/following{/other_user}","gists_url":"https://api.github.com/users/cesarandreu/gists{/gist_id}","starred_url":"https://api.github.com/users/cesarandreu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cesarandreu/subscriptions","organizations_url":"https://api.github.com/users/cesarandreu/orgs","repos_url":"https://api.github.com/users/cesarandreu/repos","events_url":"https://api.github.com/users/cesarandreu/events{/privacy}","received_events_url":"https://api.github.com/users/cesarandreu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-08-25T02:06:28Z","updated_at":"2015-08-27T18:05:45Z","closed_at":null,"body":"As an application developer, I want to extend the context with app globals, such as database instance, model instances, and other client instances (e.g. s3, redis, etc). I prefer this approach over actual globals or singletons because those options are more difficult to test.\r\n\r\nI made [koa-add-to-context](https://github.com/cesarandreu/koa-add-to-context), a middleware that mixes in keys into the request's context. However, since these values are all static, instead I could just do something like:\r\n\r\n```js\r\nObject.assign(app.context, {\r\n  models: models,\r\n  db: db,\r\n  s3: s3\r\n})\r\n```\r\n\r\nThis would be more efficient, since it lets me avoid a middleware on every request. The problem is that I'm not sure if `app.context` is considered a public API or not. If it's not, I'd propose we add an API for enhancing the application context. Thoughts?"},"comment":{"url":"https://api.github.com/repos/koajs/koa/issues/comments/135509159","html_url":"https://github.com/koajs/koa/issues/473#issuecomment-135509159","issue_url":"https://api.github.com/repos/koajs/koa/issues/473","id":135509159,"user":{"login":"aheckmann","id":166834,"avatar_url":"https://avatars.githubusercontent.com/u/166834?v=3","gravatar_id":"","url":"https://api.github.com/users/aheckmann","html_url":"https://github.com/aheckmann","followers_url":"https://api.github.com/users/aheckmann/followers","following_url":"https://api.github.com/users/aheckmann/following{/other_user}","gists_url":"https://api.github.com/users/aheckmann/gists{/gist_id}","starred_url":"https://api.github.com/users/aheckmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aheckmann/subscriptions","organizations_url":"https://api.github.com/users/aheckmann/orgs","repos_url":"https://api.github.com/users/aheckmann/repos","events_url":"https://api.github.com/users/aheckmann/events{/privacy}","received_events_url":"https://api.github.com/users/aheckmann/received_events","type":"User","site_admin":false},"created_at":"2015-08-27T18:05:45Z","updated_at":"2015-08-27T18:05:45Z","body":"and here i thought it was already public haha +1\n\nOn Thu, Aug 27, 2015 at 11:01 AM, Fangdun Cai <notifications@github.com>\nwrote:\n\n> +1, I like this way that outside the middleware.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/koajs/koa/issues/473#issuecomment-135508059>.\n>\n\n\n\n-- \nAaron\n@aaronheckmann <https://twitter.com/#!/aaronheckmann>\nsoundcloud.com/ajhecky\ngithub.com/aheckmann\n"}}