{"action":"created","issue":{"url":"https://api.github.com/repos/domokit/mojo/issues/450","labels_url":"https://api.github.com/repos/domokit/mojo/issues/450/labels{/name}","comments_url":"https://api.github.com/repos/domokit/mojo/issues/450/comments","events_url":"https://api.github.com/repos/domokit/mojo/issues/450/events","html_url":"https://github.com/domokit/mojo/issues/450","id":108431711,"number":450,"title":"Provide a more convenient way to bind local services.","user":{"login":"j9brown","id":102276,"avatar_url":"https://avatars.githubusercontent.com/u/102276?v=3","gravatar_id":"","url":"https://api.github.com/users/j9brown","html_url":"https://github.com/j9brown","followers_url":"https://api.github.com/users/j9brown/followers","following_url":"https://api.github.com/users/j9brown/following{/other_user}","gists_url":"https://api.github.com/users/j9brown/gists{/gist_id}","starred_url":"https://api.github.com/users/j9brown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j9brown/subscriptions","organizations_url":"https://api.github.com/users/j9brown/orgs","repos_url":"https://api.github.com/users/j9brown/repos","events_url":"https://api.github.com/users/j9brown/events{/privacy}","received_events_url":"https://api.github.com/users/j9brown/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-26T01:19:25Z","updated_at":"2015-09-26T02:10:13Z","closed_at":null,"body":"Currently we have to write code like the following to create an InterfaceRequest and bind it to a local implementation.  Notice that the ComponentPtr is only used to transport a value from GetProxy to the method we care about.\r\n\r\nComponentPtr component;\r\nInterfaceRequest\\<Component\\> component_request = mojo::GetProxy(&component);\r\ncomponent_manager-\\>RegisterComponent(component.Pass());\r\nnew Component(component_request.Pass());\r\n\r\nWe can simplify this by providing an inverted version of GetProxy which returns an InterfacePtr and takes an InterfaceRequest by reference instead.  Something like this:\r\n\r\ntemplate \\<typename Interface\\>\r\nInterfacePtr\\<Interface\\> GetStub(InterfaceRequest<Interface>* request) {\r\n  InterfacePtr\\<Interface\\> ptr;\r\n  *request = mojo::GetProxy(&ptr);\r\n  return ptr.Pass();\r\n}\r\n\r\nAt which point the code becomes a little simpler:\r\n\r\nInterfaceRequest\\<Component\\> component_request;\r\ncomponent_manager-\\>RegisterComponent(mojo::GetStub(&component_request));\r\nnew Component(component_request.Pass());\r\n"},"comment":{"url":"https://api.github.com/repos/domokit/mojo/issues/comments/143391368","html_url":"https://github.com/domokit/mojo/issues/450#issuecomment-143391368","issue_url":"https://api.github.com/repos/domokit/mojo/issues/450","id":143391368,"user":{"login":"j9brown","id":102276,"avatar_url":"https://avatars.githubusercontent.com/u/102276?v=3","gravatar_id":"","url":"https://api.github.com/users/j9brown","html_url":"https://github.com/j9brown","followers_url":"https://api.github.com/users/j9brown/followers","following_url":"https://api.github.com/users/j9brown/following{/other_user}","gists_url":"https://api.github.com/users/j9brown/gists{/gist_id}","starred_url":"https://api.github.com/users/j9brown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j9brown/subscriptions","organizations_url":"https://api.github.com/users/j9brown/orgs","repos_url":"https://api.github.com/users/j9brown/repos","events_url":"https://api.github.com/users/j9brown/events{/privacy}","received_events_url":"https://api.github.com/users/j9brown/received_events","type":"User","site_admin":false},"created_at":"2015-09-26T02:10:13Z","updated_at":"2015-09-26T02:10:13Z","body":"Ah that's true.  This was following an example in interface_request.h.\nMaybe I should just update that.\n\nOn Fri, Sep 25, 2015, 7:01 PM Viet-Trung Luu <notifications@github.com>\nwrote:\n\n> Why don't you just do:\n>\n> ComponentPtr component;\n> new Component(GetProxy(&component));\n> component_manager->RegisterComponent(component.Pass());\n>\n> This is essentially equivalent (i.e., equivalent, unless you're doing bad\n> things).\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/domokit/mojo/issues/450#issuecomment-143391003>.\n>\n"}}