{"action":"created","issue":{"url":"https://api.github.com/repos/modesttree/Zenject/issues/38","labels_url":"https://api.github.com/repos/modesttree/Zenject/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/modesttree/Zenject/issues/38/comments","events_url":"https://api.github.com/repos/modesttree/Zenject/issues/38/events","html_url":"https://github.com/modesttree/Zenject/issues/38","id":71743034,"number":38,"title":"Fallback Containers and Optional Injectables","user":{"login":"bvance","id":2539501,"avatar_url":"https://avatars.githubusercontent.com/u/2539501?v=3","gravatar_id":"","url":"https://api.github.com/users/bvance","html_url":"https://github.com/bvance","followers_url":"https://api.github.com/users/bvance/followers","following_url":"https://api.github.com/users/bvance/following{/other_user}","gists_url":"https://api.github.com/users/bvance/gists{/gist_id}","starred_url":"https://api.github.com/users/bvance/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvance/subscriptions","organizations_url":"https://api.github.com/users/bvance/orgs","repos_url":"https://api.github.com/users/bvance/repos","events_url":"https://api.github.com/users/bvance/events{/privacy}","received_events_url":"https://api.github.com/users/bvance/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-29T00:20:34Z","updated_at":"2015-04-29T16:19:01Z","closed_at":null,"body":"It looks like you guys decided to make it so 'optional' contexts will not fall back to 'parent' containers should they fail to find an appropriate binding in the base container. Is there any reason you decided to go that way?\r\n\r\nI'm working on some experimental code using Zenject and it seems to me like it would be far more helpful if DiContainers searched fallbacks for optional bindings the same as they do for mandatory ones (simply returning null if no bindings are found therein)."},"comment":{"url":"https://api.github.com/repos/modesttree/Zenject/issues/comments/97485912","html_url":"https://github.com/modesttree/Zenject/issues/38#issuecomment-97485912","issue_url":"https://api.github.com/repos/modesttree/Zenject/issues/38","id":97485912,"user":{"login":"svermeulen","id":810762,"avatar_url":"https://avatars.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":"2015-04-29T16:19:01Z","updated_at":"2015-04-29T16:19:01Z","body":"Yes, I agree that it should work that way\r\n\r\nThe way nested containers work in Zenject still needs some improvement and best practices/etc. still need to be worked out.  Right now, a parent container is treated as a 'fallback'.  I think this is great for single dependencies to allow you to override a binding from a higher-level container in a lower-level container, but for list dependencies I don't think this really makes sense.\r\n\r\nRight now, when a dependency of type `List<Foo>` is marked as optional, and there are no Foo's bound to the container, then an empty list is injected.  If there are Foo's bound to a parent container, they will not be added to the list.  It will only look up lists in the parent if the list is not marked as optional and there are no matches in the current container.\r\n\r\nHowever, as I said I think it would be better if lists just always collected all dependencies from the current container and parents.  This way the concept is much more intuitive and you can think of as the nested containers \"inheriting\" all bindings from their parents rather than using their parent as a \"fallback\".\r\n\r\nThere are some changes I need to make to make this happen - in particular, the way the global composition root stuff works.  I will leave this item open until I am able to address it.\r\n\r\nSide note:  Having proper support for nested containers would also mean I can get rid of the concept of \"Bind Scope\" since we can just have a CreateNestedContainer() method and use that instead.  It would also make the DiContainer more thread-safe and just overall be much cleaner"}}