{"action":"created","issue":{"url":"https://api.github.com/repos/modesttree/Zenject/issues/294","repository_url":"https://api.github.com/repos/modesttree/Zenject","labels_url":"https://api.github.com/repos/modesttree/Zenject/issues/294/labels{/name}","comments_url":"https://api.github.com/repos/modesttree/Zenject/issues/294/comments","events_url":"https://api.github.com/repos/modesttree/Zenject/issues/294/events","html_url":"https://github.com/modesttree/Zenject/issues/294","id":240536614,"number":294,"title":"Inheriting bindings?","user":{"login":"suzdalnitski","id":8169977,"avatar_url":"https://avatars1.githubusercontent.com/u/8169977?v=3","gravatar_id":"","url":"https://api.github.com/users/suzdalnitski","html_url":"https://github.com/suzdalnitski","followers_url":"https://api.github.com/users/suzdalnitski/followers","following_url":"https://api.github.com/users/suzdalnitski/following{/other_user}","gists_url":"https://api.github.com/users/suzdalnitski/gists{/gist_id}","starred_url":"https://api.github.com/users/suzdalnitski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suzdalnitski/subscriptions","organizations_url":"https://api.github.com/users/suzdalnitski/orgs","repos_url":"https://api.github.com/users/suzdalnitski/repos","events_url":"https://api.github.com/users/suzdalnitski/events{/privacy}","received_events_url":"https://api.github.com/users/suzdalnitski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-05T04:44:29Z","updated_at":"2017-07-10T15:11:21Z","closed_at":null,"body":"I have a complex object, and I would like to refactor some parts of it to a separate class. Is it possible somehow to have the new class inherit the bindings from the original object?\r\n\r\nBefore:\r\n```\r\npublic class Button : MonoBehaviour {\r\n   [Inject(Id=\"on\")] UIWidget _onWidget;\r\n   [Inject(Id=\"off\")] UIWidget _offWidget;\r\n}\r\n```\r\n\r\nAfter:\r\n```\r\npublic class Button : MonoBehaviour {\r\n   public class Presentation {\r\n      [Inject(Id=\"on\")] UIWidget _onWidget;\r\n      [Inject(Id=\"off\")] UIWidget _offWidget;\r\n   }\r\n\r\n   private Presentation _presentation;\r\n}\r\n```\r\n\r\nThe bindings are as follows:\r\n```\r\nContainer.Bind<UIWidget>().WithId(\"on\").FromComponentInChildren(p => p.gameObject.name == \"On\", true).WhenInjectedInto<Button>();\r\nContainer.Bind<UIWidget>().WithId(\"off\").FromComponentInChildren(p => p.gameObject.name == \"Off\", true).WhenInjectedInto<Button>();\r\n```\r\n\r\nHow can I make sure that Button.Presentation inherits the bindings from Button? Thank you."},"comment":{"url":"https://api.github.com/repos/modesttree/Zenject/issues/comments/314136357","html_url":"https://github.com/modesttree/Zenject/issues/294#issuecomment-314136357","issue_url":"https://api.github.com/repos/modesttree/Zenject/issues/294","id":314136357,"user":{"login":"svermeulen","id":810762,"avatar_url":"https://avatars0.githubusercontent.com/u/810762?v=3","gravatar_id":"","url":"https://api.github.com/users/svermeulen","html_url":"https://github.com/svermeulen","followers_url":"https://api.github.com/users/svermeulen/followers","following_url":"https://api.github.com/users/svermeulen/following{/other_user}","gists_url":"https://api.github.com/users/svermeulen/gists{/gist_id}","starred_url":"https://api.github.com/users/svermeulen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svermeulen/subscriptions","organizations_url":"https://api.github.com/users/svermeulen/orgs","repos_url":"https://api.github.com/users/svermeulen/repos","events_url":"https://api.github.com/users/svermeulen/events{/privacy}","received_events_url":"https://api.github.com/users/svermeulen/received_events","type":"User","site_admin":false},"created_at":"2017-07-10T15:11:21Z","updated_at":"2017-07-10T15:11:21Z","body":"Changing FromBinderGeneric.FromComponentInChildren to this allows what you're doing to work:\r\n\r\n```\r\npublic ScopeArgConditionCopyNonLazyBinder FromComponentInChildren(\r\n    bool excludeSelf = false, Func<TContract, bool> predicate = null, bool includeInactive = false)\r\n{\r\n    BindingUtil.AssertIsInterfaceOrComponent(AllParentTypes);\r\n\r\n    return FromMethodMultiple((ctx) => {\r\n        MonoBehaviour monoBehaviourContext = null;\r\n\r\n        foreach (var ancestorContext in ctx.ParentContextsAndSelf)\r\n        {\r\n            if (ancestorContext.ObjectInstance != null && ancestorContext.ObjectType.DerivesFromOrEqual<MonoBehaviour>())\r\n            {\r\n                monoBehaviourContext = (MonoBehaviour)ancestorContext.ObjectInstance;\r\n                break;\r\n            }\r\n        }\r\n\r\n        Assert.IsNotNull(monoBehaviourContext);\r\n\r\n        var res = monoBehaviourContext.GetComponentsInChildren<TContract>(includeInactive)\r\n             .Where(x => !ReferenceEquals(x, monoBehaviourContext));\r\n\r\n        if (excludeSelf)\r\n        {\r\n            res = res.Where(x => (x as Component).gameObject != monoBehaviourContext.gameObject);\r\n        }\r\n\r\n        if (predicate != null)\r\n        {\r\n            res = res.Where(predicate);\r\n        }\r\n\r\n        return res;\r\n    });\r\n}\r\n```\r\n\r\nI didn't make this change to the source yet because I'm not sure what implication it has and whether it's really a good idea.  It could result in some unexpected behaviour potentially.\r\n"}}
{"actor":{"display_login":"svermeulen"}}