{"action":"created","issue":{"url":"https://api.github.com/repos/modesttree/Zenject/issues/49","labels_url":"https://api.github.com/repos/modesttree/Zenject/issues/49/labels{/name}","comments_url":"https://api.github.com/repos/modesttree/Zenject/issues/49/comments","events_url":"https://api.github.com/repos/modesttree/Zenject/issues/49/events","html_url":"https://github.com/modesttree/Zenject/issues/49","id":106116823,"number":49,"title":"Suggestion for optional parameters with constructor injection","user":{"login":"kruncher","id":554215,"avatar_url":"https://avatars.githubusercontent.com/u/554215?v=3","gravatar_id":"","url":"https://api.github.com/users/kruncher","html_url":"https://github.com/kruncher","followers_url":"https://api.github.com/users/kruncher/followers","following_url":"https://api.github.com/users/kruncher/following{/other_user}","gists_url":"https://api.github.com/users/kruncher/gists{/gist_id}","starred_url":"https://api.github.com/users/kruncher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kruncher/subscriptions","organizations_url":"https://api.github.com/users/kruncher/orgs","repos_url":"https://api.github.com/users/kruncher/repos","events_url":"https://api.github.com/users/kruncher/events{/privacy}","received_events_url":"https://api.github.com/users/kruncher/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-12T00:39:01Z","updated_at":"2015-09-14T08:23:03Z","closed_at":null,"body":"I've bumped into this a couple of times and feel that it would be quite nice if Zenject was able to determine whether a constructor dependency was optional when a default parameter value is present:\r\n\r\n```\r\npublic class Foo {\r\n    ...\r\n    public Foo(IBar bar, IBaz baz = null) {\r\n        ...\r\n    }\r\n}\r\n```\r\n\r\nRather than just throwing the following exception:\r\n```\r\nZenjectResolveException: Unable to resolve type 'IBaz' while building object with type 'Foo'. \r\n```\r\n\r\nIdeally I would prefer to avoid annotating these parameters with an attribute since this can already be deduced using reflection like the following:\r\n```\r\nif (injectedParameterValue == null) {\r\n    bool isOptionalParameter = parameterInfo.IsOptional || ReflectionUtility.HasZenjectOptionalAttribute(parameterInfo);\r\n    if (!isOptionalParameter)\r\n        throw new ZenjectResolveException();\r\n\r\n    // `Type.Missing` is suggested in MSDN (probably to avoid boxing on value types):\r\n    // https://msdn.microsoft.com/en-us/library/system.type.missing(v=vs.110).aspx\r\n    injectedParameterValue = Type.Missing;\r\n}\r\n```\r\n\r\nIs this something that can be added?\r\n\r\nMany thanks!"},"comment":{"url":"https://api.github.com/repos/modesttree/Zenject/issues/comments/139996493","html_url":"https://github.com/modesttree/Zenject/issues/49#issuecomment-139996493","issue_url":"https://api.github.com/repos/modesttree/Zenject/issues/49","id":139996493,"user":{"login":"Givemeyourgits","id":1454872,"avatar_url":"https://avatars.githubusercontent.com/u/1454872?v=3","gravatar_id":"","url":"https://api.github.com/users/Givemeyourgits","html_url":"https://github.com/Givemeyourgits","followers_url":"https://api.github.com/users/Givemeyourgits/followers","following_url":"https://api.github.com/users/Givemeyourgits/following{/other_user}","gists_url":"https://api.github.com/users/Givemeyourgits/gists{/gist_id}","starred_url":"https://api.github.com/users/Givemeyourgits/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Givemeyourgits/subscriptions","organizations_url":"https://api.github.com/users/Givemeyourgits/orgs","repos_url":"https://api.github.com/users/Givemeyourgits/repos","events_url":"https://api.github.com/users/Givemeyourgits/events{/privacy}","received_events_url":"https://api.github.com/users/Givemeyourgits/received_events","type":"User","site_admin":false},"created_at":"2015-09-14T08:23:03Z","updated_at":"2015-09-14T08:23:03Z","body":"I would find this handy as well."}}