{"action":"created","issue":{"url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/320","repository_url":"https://api.github.com/repos/JeremySkinner/FluentValidation","labels_url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/320/labels{/name}","comments_url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/320/comments","events_url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/320/events","html_url":"https://github.com/JeremySkinner/FluentValidation/issues/320","id":174607726,"number":320,"title":"Setting validators for collection of subclassed object using the PolymorphicValidator","user":{"login":"MauricioArroyo","id":12821840,"avatar_url":"https://avatars.githubusercontent.com/u/12821840?v=3","gravatar_id":"","url":"https://api.github.com/users/MauricioArroyo","html_url":"https://github.com/MauricioArroyo","followers_url":"https://api.github.com/users/MauricioArroyo/followers","following_url":"https://api.github.com/users/MauricioArroyo/following{/other_user}","gists_url":"https://api.github.com/users/MauricioArroyo/gists{/gist_id}","starred_url":"https://api.github.com/users/MauricioArroyo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MauricioArroyo/subscriptions","organizations_url":"https://api.github.com/users/MauricioArroyo/orgs","repos_url":"https://api.github.com/users/MauricioArroyo/repos","events_url":"https://api.github.com/users/MauricioArroyo/events{/privacy}","received_events_url":"https://api.github.com/users/MauricioArroyo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-01T19:38:26Z","updated_at":"2016-09-06T09:27:47Z","closed_at":null,"body":"Hi @JeremySkinner,\r\nOnce again, thank you for your hard work on this great library!\r\n \r\nThis is related to Issue #111 \r\nI have the following issue and I can't figure out what I am doing wrong. \r\n\r\nI am using the Polymorphic Validator in the following classes and validators.\r\n\r\n```javascript\r\n    public class A\r\n    {\r\n        public List<A> Children { get; set; }\r\n    }\r\n\r\n    public class SomeFoo : A\r\n    {\r\n        public int Bar { get; set; }\r\n    }\r\n\r\n    public class AnotherFoo : A\r\n    {\r\n        public int Whatever { get; set; }\r\n    }\r\n\r\n    public class SomeFooValidator : AValidator<SomeFoo>\r\n    {\r\n        public SomeFooValidator(IExternalService service):base(service)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class SomeAnotherValidator : AValidator<AnotherFoo>\r\n    {\r\n        public SomeAnotherValidator(IExternalService service):base(service)\r\n        {\r\n        }\r\n    }\r\n\r\n    public class AValidator<T> : AbstractValidator<T> where T:A\r\n    {\r\n        public AValidator(IExternalService service)\r\n        {\r\n            RuleFor(p => p.Children).SetValidator(new PolymorphicValidator<A>()\r\n                .Add(new SomeFooValidator(service))\r\n                .Add(new SomeAnotherValidator(service))\r\n            );\r\n        }\r\n    }\r\n```\r\nI get a stackoverflow error when trying to use the validators, because of the children list.\r\n\r\nI thought about declaring the child validators as static variables so I inject the same on the PolymorphicValidator all the time, the problem here would be the external service which gets injected in the AValidator and has to be passed along to the child validators.\r\n\r\nI am looking into this, but I thought maybe I am not the first person who had this issue...\r\n\r\nIf you can take a look I will really appreciate it!\r\n\r\nThanks in advance."},"comment":{"url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/comments/244897970","html_url":"https://github.com/JeremySkinner/FluentValidation/issues/320#issuecomment-244897970","issue_url":"https://api.github.com/repos/JeremySkinner/FluentValidation/issues/320","id":244897970,"user":{"login":"JeremySkinner","id":90130,"avatar_url":"https://avatars.githubusercontent.com/u/90130?v=3","gravatar_id":"","url":"https://api.github.com/users/JeremySkinner","html_url":"https://github.com/JeremySkinner","followers_url":"https://api.github.com/users/JeremySkinner/followers","following_url":"https://api.github.com/users/JeremySkinner/following{/other_user}","gists_url":"https://api.github.com/users/JeremySkinner/gists{/gist_id}","starred_url":"https://api.github.com/users/JeremySkinner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeremySkinner/subscriptions","organizations_url":"https://api.github.com/users/JeremySkinner/orgs","repos_url":"https://api.github.com/users/JeremySkinner/repos","events_url":"https://api.github.com/users/JeremySkinner/events{/privacy}","received_events_url":"https://api.github.com/users/JeremySkinner/received_events","type":"User","site_admin":false},"created_at":"2016-09-06T09:27:47Z","updated_at":"2016-09-06T09:27:47Z","body":"I would've just passed the dependency down from the parent validator into the custom validator's constructor."}}
{"actor":{"display_login":"JeremySkinner"}}