{"action":"created","issue":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/119","labels_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/119/comments","events_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/119/events","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/119","id":104833123,"number":119,"title":"Allow RegisterCollection to ignore composite types","user":{"login":"dhilgarth","id":1180105,"avatar_url":"https://avatars.githubusercontent.com/u/1180105?v=3","gravatar_id":"","url":"https://api.github.com/users/dhilgarth","html_url":"https://github.com/dhilgarth","followers_url":"https://api.github.com/users/dhilgarth/followers","following_url":"https://api.github.com/users/dhilgarth/following{/other_user}","gists_url":"https://api.github.com/users/dhilgarth/gists{/gist_id}","starred_url":"https://api.github.com/users/dhilgarth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhilgarth/subscriptions","organizations_url":"https://api.github.com/users/dhilgarth/orgs","repos_url":"https://api.github.com/users/dhilgarth/repos","events_url":"https://api.github.com/users/dhilgarth/events{/privacy}","received_events_url":"https://api.github.com/users/dhilgarth/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/labels/feature","name":"feature","color":"0052cc"},{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/labels/task","name":"task","color":"5319e7"}],"state":"closed","locked":false,"assignee":{"login":"dotnetjunkie","id":1506621,"avatar_url":"https://avatars.githubusercontent.com/u/1506621?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnetjunkie","html_url":"https://github.com/dotnetjunkie","followers_url":"https://api.github.com/users/dotnetjunkie/followers","following_url":"https://api.github.com/users/dotnetjunkie/following{/other_user}","gists_url":"https://api.github.com/users/dotnetjunkie/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnetjunkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnetjunkie/subscriptions","organizations_url":"https://api.github.com/users/dotnetjunkie/orgs","repos_url":"https://api.github.com/users/dotnetjunkie/repos","events_url":"https://api.github.com/users/dotnetjunkie/events{/privacy}","received_events_url":"https://api.github.com/users/dotnetjunkie/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/milestones/2","html_url":"https://github.com/simpleinjector/SimpleInjector/milestones/Simple%20Injector%20v3.1","labels_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/milestones/2/labels","id":1266676,"number":2,"title":"Simple Injector v3.1","description":"","creator":{"login":"dotnetjunkie","id":1506621,"avatar_url":"https://avatars.githubusercontent.com/u/1506621?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnetjunkie","html_url":"https://github.com/dotnetjunkie","followers_url":"https://api.github.com/users/dotnetjunkie/followers","following_url":"https://api.github.com/users/dotnetjunkie/following{/other_user}","gists_url":"https://api.github.com/users/dotnetjunkie/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnetjunkie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnetjunkie/subscriptions","organizations_url":"https://api.github.com/users/dotnetjunkie/orgs","repos_url":"https://api.github.com/users/dotnetjunkie/repos","events_url":"https://api.github.com/users/dotnetjunkie/events{/privacy}","received_events_url":"https://api.github.com/users/dotnetjunkie/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":4,"state":"open","created_at":"2015-08-21T17:27:09Z","updated_at":"2015-09-19T10:06:50Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2015-09-04T05:35:01Z","updated_at":"2015-09-19T16:17:56Z","closed_at":"2015-09-19T10:06:50Z","body":"I try to avoid working with enumerables of my interfaces where I just have to execute a method on each instance. Instead, I am using a composite, so that the caller just has to deal with one instance.\r\nSo, what I often do is this:\r\n\r\n``` c#\r\ncontainer.RegisterCollection<IStartUpHandler>(relevantAssemblies);\r\ncontainer.RegisterSingleton<IStartUpHandler, CompositeStartUpHandler>();\r\n```\r\n\r\nThe problem here is that `RegisterCollection` also registers the `CompositeStartUpHandler` which will result in a `CyclicDependency...Exception`, when trying to get an instance of `IStartUpHandler`.\r\n\r\nRight now, I am using my own helper method that ignores composites:\r\n\r\n``` c#\r\nvar behavior = container.Options.ConstructorResolutionBehavior;\r\n\r\nvar types = \r\n    from assembly in assemblies\r\n    from type in assembly.GetTypes()\r\n    where typeof(TService).IsAssignableFrom(type)\r\n    where !type.IsAbstract\r\n    where !type.IsGenericTypeDefinition\r\n    where !IsCompositeOf<TService>(type, behavior)\r\n    select type;\r\n\r\ncontainer.RegisterCollection<TService>(types);\r\n```\r\n\r\nWith `IsCompositeOf` being implemented like this:\r\n\r\n``` c#\r\nstatic bool IsCompositeOf<TService>(Type type, IConstructorResolutionBehavior behavior)\r\n{\r\n    var ctor = behavior.GetConstructor(typeof(TService), type);\r\n\r\n    return ctor.GetParameters().Any(p => p.ParameterType == typeof(IEnumerable<TService>));\r\n}\r\n```\r\n\r\nIt would be nice, if this would somehow make it into the core code-base."},"comment":{"url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/comments/141684641","html_url":"https://github.com/simpleinjector/SimpleInjector/issues/119#issuecomment-141684641","issue_url":"https://api.github.com/repos/simpleinjector/SimpleInjector/issues/119","id":141684641,"user":{"login":"dhilgarth","id":1180105,"avatar_url":"https://avatars.githubusercontent.com/u/1180105?v=3","gravatar_id":"","url":"https://api.github.com/users/dhilgarth","html_url":"https://github.com/dhilgarth","followers_url":"https://api.github.com/users/dhilgarth/followers","following_url":"https://api.github.com/users/dhilgarth/following{/other_user}","gists_url":"https://api.github.com/users/dhilgarth/gists{/gist_id}","starred_url":"https://api.github.com/users/dhilgarth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhilgarth/subscriptions","organizations_url":"https://api.github.com/users/dhilgarth/orgs","repos_url":"https://api.github.com/users/dhilgarth/repos","events_url":"https://api.github.com/users/dhilgarth/events{/privacy}","received_events_url":"https://api.github.com/users/dhilgarth/received_events","type":"User","site_admin":false},"created_at":"2015-09-19T16:17:55Z","updated_at":"2015-09-19T16:17:55Z","body":"Thanks! :)"}}