{"action":"created","issue":{"url":"https://api.github.com/repos/castleproject/Windsor/issues/415","repository_url":"https://api.github.com/repos/castleproject/Windsor","labels_url":"https://api.github.com/repos/castleproject/Windsor/issues/415/labels{/name}","comments_url":"https://api.github.com/repos/castleproject/Windsor/issues/415/comments","events_url":"https://api.github.com/repos/castleproject/Windsor/issues/415/events","html_url":"https://github.com/castleproject/Windsor/issues/415","id":337068939,"node_id":"MDU6SXNzdWUzMzcwNjg5Mzk=","number":415,"title":"Delegate factory with Dependency.OnComponent and TypedFactoryFacility","user":{"login":"Qwetek","id":6096674,"node_id":"MDQ6VXNlcjYwOTY2NzQ=","avatar_url":"https://avatars2.githubusercontent.com/u/6096674?v=4","gravatar_id":"","url":"https://api.github.com/users/Qwetek","html_url":"https://github.com/Qwetek","followers_url":"https://api.github.com/users/Qwetek/followers","following_url":"https://api.github.com/users/Qwetek/following{/other_user}","gists_url":"https://api.github.com/users/Qwetek/gists{/gist_id}","starred_url":"https://api.github.com/users/Qwetek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Qwetek/subscriptions","organizations_url":"https://api.github.com/users/Qwetek/orgs","repos_url":"https://api.github.com/users/Qwetek/repos","events_url":"https://api.github.com/users/Qwetek/events{/privacy}","received_events_url":"https://api.github.com/users/Qwetek/received_events","type":"User","site_admin":false},"labels":[{"id":536647587,"node_id":"MDU6TGFiZWw1MzY2NDc1ODc=","url":"https://api.github.com/repos/castleproject/Windsor/labels/discussion","name":"discussion","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":20,"created_at":"2018-06-29T16:54:11Z","updated_at":"2018-07-03T00:32:07Z","closed_at":null,"author_association":"NONE","body":"Hello, i have been doing some refactoring of our container mess and it seems i found something weird. When using delegate factory and Dependecny.OnComponent at once the factory gets wrong component resolved, i boiled it down to this code:\r\n```c#\r\npublic interface IInterface {}\r\npublic class C1 : IInterface {}\r\npublic class C2 : IInterface {}\r\npublic  class Root\r\n{\r\n  private IInterface _I;\r\n  public Root(Func<IInterface> factory)\r\n    {\r\n\t  //here i expect to get instance of C2 but get C1\r\n      _I = factory();\r\n    }\r\n}\r\n\r\npublic void Main()\r\n{\r\n  _container = new WindsorContainer();\r\n  _container.AddFacility<TypedFactoryFacility>();\r\n  \r\n  _container.Register(\r\n  \tComponent.For<IInterface>().ImplementedBy<C1>(),\r\n  \tComponent.For<IInterface>().ImplementedBy<C2>(),\r\n  \tComponent.For<Root>().DependsOn(Dependency.OnComponent<IInterface, C2>())\r\n  );\r\n  \r\n  var t = _container.Resolve<Root>();\r\n}\r\n```\r\n\r\nI used a workaround with DependencyOnValue and created the delegate factory myself, but thats ugly:\r\n\r\n`Component.For<Root>().DependsOn(Dependency.OnValue<Func<IInterface>>((Func<IInterface>)(_ => new C2())`\r\n\r\nSo am i doing something wrong ? Or is it a bug ? Or maybe its by design ? Is there a better way than the Dependency.OnValue ?\r\nNote: this example is verry simplified and sadly refactoring the classes is out of the question.\r\nNote2: the delgate (Func<IInterface>) in my case takes arguments, i just removed them because they are not neccesary for the example\r\n\r\nversion 4.0.30319 (i know its not the newest, but i work with what i have and if neccesary i can upgrade )"},"comment":{"url":"https://api.github.com/repos/castleproject/Windsor/issues/comments/401977172","html_url":"https://github.com/castleproject/Windsor/issues/415#issuecomment-401977172","issue_url":"https://api.github.com/repos/castleproject/Windsor/issues/415","id":401977172,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMTk3NzE3Mg==","user":{"login":"fir3pho3nixx","id":607402,"node_id":"MDQ6VXNlcjYwNzQwMg==","avatar_url":"https://avatars2.githubusercontent.com/u/607402?v=4","gravatar_id":"","url":"https://api.github.com/users/fir3pho3nixx","html_url":"https://github.com/fir3pho3nixx","followers_url":"https://api.github.com/users/fir3pho3nixx/followers","following_url":"https://api.github.com/users/fir3pho3nixx/following{/other_user}","gists_url":"https://api.github.com/users/fir3pho3nixx/gists{/gist_id}","starred_url":"https://api.github.com/users/fir3pho3nixx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fir3pho3nixx/subscriptions","organizations_url":"https://api.github.com/users/fir3pho3nixx/orgs","repos_url":"https://api.github.com/users/fir3pho3nixx/repos","events_url":"https://api.github.com/users/fir3pho3nixx/events{/privacy}","received_events_url":"https://api.github.com/users/fir3pho3nixx/received_events","type":"User","site_admin":false},"created_at":"2018-07-03T00:32:07Z","updated_at":"2018-07-03T00:32:07Z","author_association":"CONTRIBUTOR","body":"Submit a PR in 3 months or I will close this issue. "}}
{"actor":{"display_login":"fir3pho3nixx"}}