{"action":"created","issue":{"url":"https://api.github.com/repos/rebus-org/Rebus.SimpleInjector/issues/3","repository_url":"https://api.github.com/repos/rebus-org/Rebus.SimpleInjector","labels_url":"https://api.github.com/repos/rebus-org/Rebus.SimpleInjector/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/rebus-org/Rebus.SimpleInjector/issues/3/comments","events_url":"https://api.github.com/repos/rebus-org/Rebus.SimpleInjector/issues/3/events","html_url":"https://github.com/rebus-org/Rebus.SimpleInjector/issues/3","id":280362391,"number":3,"title":"Rebus.SimpleInjector does not support polymorphic dispatch","user":{"login":"MrMDavidson","id":1366249,"avatar_url":"https://avatars3.githubusercontent.com/u/1366249?v=4","gravatar_id":"","url":"https://api.github.com/users/MrMDavidson","html_url":"https://github.com/MrMDavidson","followers_url":"https://api.github.com/users/MrMDavidson/followers","following_url":"https://api.github.com/users/MrMDavidson/following{/other_user}","gists_url":"https://api.github.com/users/MrMDavidson/gists{/gist_id}","starred_url":"https://api.github.com/users/MrMDavidson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrMDavidson/subscriptions","organizations_url":"https://api.github.com/users/MrMDavidson/orgs","repos_url":"https://api.github.com/users/MrMDavidson/repos","events_url":"https://api.github.com/users/MrMDavidson/events{/privacy}","received_events_url":"https://api.github.com/users/MrMDavidson/received_events","type":"User","site_admin":false},"labels":[{"id":434178437,"url":"https://api.github.com/repos/rebus-org/Rebus.SimpleInjector/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"open","locked":false,"assignee":{"login":"mookid8000","id":32968,"avatar_url":"https://avatars1.githubusercontent.com/u/32968?v=4","gravatar_id":"","url":"https://api.github.com/users/mookid8000","html_url":"https://github.com/mookid8000","followers_url":"https://api.github.com/users/mookid8000/followers","following_url":"https://api.github.com/users/mookid8000/following{/other_user}","gists_url":"https://api.github.com/users/mookid8000/gists{/gist_id}","starred_url":"https://api.github.com/users/mookid8000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mookid8000/subscriptions","organizations_url":"https://api.github.com/users/mookid8000/orgs","repos_url":"https://api.github.com/users/mookid8000/repos","events_url":"https://api.github.com/users/mookid8000/events{/privacy}","received_events_url":"https://api.github.com/users/mookid8000/received_events","type":"User","site_admin":false},"assignees":[{"login":"mookid8000","id":32968,"avatar_url":"https://avatars1.githubusercontent.com/u/32968?v=4","gravatar_id":"","url":"https://api.github.com/users/mookid8000","html_url":"https://github.com/mookid8000","followers_url":"https://api.github.com/users/mookid8000/followers","following_url":"https://api.github.com/users/mookid8000/following{/other_user}","gists_url":"https://api.github.com/users/mookid8000/gists{/gist_id}","starred_url":"https://api.github.com/users/mookid8000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mookid8000/subscriptions","organizations_url":"https://api.github.com/users/mookid8000/orgs","repos_url":"https://api.github.com/users/mookid8000/repos","events_url":"https://api.github.com/users/mookid8000/events{/privacy}","received_events_url":"https://api.github.com/users/mookid8000/received_events","type":"User","site_admin":false}],"milestone":null,"comments":6,"created_at":"2017-12-08T03:52:26Z","updated_at":"2017-12-14T03:40:42Z","closed_at":null,"author_association":"NONE","body":"Just a heads up... the implementation of `SimpleInjectorAdapter` does not support polymorphic dispatch. If you have `CustomerCreatedEvent` -> `BaseCustomerEvent` -> `Event` then handlers for `BaseCustomerEvent` and `Event` would not ever be invoked. In particular this breaks second level retries as the container attempts to resolve a `Rebus.Retry.Simple.FailedMessageWrapper<TMessageType>` which is a private class and thus cannot ever be implemented by consumers of the Rebus library. (They'd instead be implementing an `IHandleMessages<IFailed<TMessageType>>`.\r\n\r\nThe offending code is https://github.com/rebus-org/Rebus.SimpleInjector/blob/master/Rebus.SimpleInjector/SimpleInjectorContainerAdapter.cs#L56. If you contrast this to your other IoC libraries you'll note they get the base types and enumerate the base types and resolve the handlers for each type. Eg.\r\nhttps://github.com/rebus-org/Rebus.CastleWindsor/blob/master/Rebus.CastleWindsor/Config/CastleWindsorContainerAdapter.cs#L111\r\n\r\nGiven this needs to be implemented in every container implementation I wonder if it's worth while providing a base / helper class for this in Rebus core.\r\n\r\n```C#\r\npublic class BaseContainerAdapter : IContainerAdapter {\r\n  public virtual async Task<IEnumerable<IHandleMessages<TMessage>>> GetHandlers<TMessage>(TMessage message, ITransactionContext transactionContext) {\r\n    Type openMessageType = typeof(IHandleMessages<>);\r\n    return GetMessageTypes(message)\r\n      .SelectMany(type => GetHandlersForType(type))\r\n      .ToList();\r\n  }\r\n\r\n  protected abstract Task<IEnumerable<Type>> GetHandlersForType(TMessage type, ITransactionContext transactionContext);\r\n\r\n  protected IEnumerable<Type> GetMessageTypes<TMessageType>(TMessageType message) {\r\n    return typeof(TMessageType).GetBaseTypes()\r\n      .Concat(new [] { typeof(TMessageType) } )\r\n      .ToList();\r\n  }\r\n}\r\n```\r\n\r\nThis way if a specific IoC supported resolving for all derived types automatically an implementer could just override `GetHandlers`. Otherwise they can just implement `GetHandlersForType` and only need to worry about resolving for the given type (Eg. `CustomerCreatedEvent`, `BaseCustomerEvent`, `Event` each time its called).\r\n\r\nNote: The `BaseContainerAdapter` class was written straight into the GitHub issue so likely isn't perfect but I'm sure you get the idea :)"},"comment":{"url":"https://api.github.com/repos/rebus-org/Rebus.SimpleInjector/issues/comments/351599754","html_url":"https://github.com/rebus-org/Rebus.SimpleInjector/issues/3#issuecomment-351599754","issue_url":"https://api.github.com/repos/rebus-org/Rebus.SimpleInjector/issues/3","id":351599754,"user":{"login":"MrMDavidson","id":1366249,"avatar_url":"https://avatars3.githubusercontent.com/u/1366249?v=4","gravatar_id":"","url":"https://api.github.com/users/MrMDavidson","html_url":"https://github.com/MrMDavidson","followers_url":"https://api.github.com/users/MrMDavidson/followers","following_url":"https://api.github.com/users/MrMDavidson/following{/other_user}","gists_url":"https://api.github.com/users/MrMDavidson/gists{/gist_id}","starred_url":"https://api.github.com/users/MrMDavidson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrMDavidson/subscriptions","organizations_url":"https://api.github.com/users/MrMDavidson/orgs","repos_url":"https://api.github.com/users/MrMDavidson/repos","events_url":"https://api.github.com/users/MrMDavidson/events{/privacy}","received_events_url":"https://api.github.com/users/MrMDavidson/received_events","type":"User","site_admin":false},"created_at":"2017-12-14T03:40:42Z","updated_at":"2017-12-14T03:40:42Z","author_association":"NONE","body":"I'm fairly confident it is but haven't been able to narrow it down to an exact repro case. Given how old a version of SimpleInjector we're on I'm happy to just close this."}}
{"actor":{"display_login":"MrMDavidson"}}