{"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":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-29T16:54:11Z","updated_at":"2018-06-29T22:22:56Z","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/401488484","html_url":"https://github.com/castleproject/Windsor/issues/415#issuecomment-401488484","issue_url":"https://api.github.com/repos/castleproject/Windsor/issues/415","id":401488484,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMTQ4ODQ4NA==","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-06-29T22:22:56Z","updated_at":"2018-06-29T22:22:56Z","author_association":"CONTRIBUTOR","body":"Ok, when you register IInterface twice with two components C1 and C2 what exactly are you expecting to happen via the dependency resolve graph? \r\n\r\nDoes the C1 registration supersede C2 or vice versa? What happens with a IInterface dependency? Do we need an array resolver? \r\n\r\nYour registration code is a little confusing. Sorry! "}}
{"actor":{"display_login":"fir3pho3nixx"}}