title: Registering Decorators conflicts with registration of IEnumerable<T>
body: <p>I am using simpleinjector 2.3.0.0 and .net 4.5.</p>
  
  <p>I have been trying to register a Factory which has a dependency on a IEnumerable, and an instance of a Thing, plus a unitofwork decorator. (among other things)</p>
  
  <p>Here is my factory:</p>
  
  <pre><code>public class ThingFactory : IThingFactory
  {
      private readonly IEnumerable&lt;IThing&gt; things;
  
      public ThingFactory (IEnumerable&lt;IThing&gt; things)
      {
          this.things= things;
      }
  
      public IThing GetThing(ThingType thingType)
      {
       return things.FirstOrDefault(t =&gt; t.IsApplicable(thingType));
      }
  }
  </code></pre>
  
  <p>and here is my implementation of IThing</p>
  
  <pre><code> public class ThingOne: IThing
  {
       private IThingFactory thingFactory;
  
      public ThingOne(IThingFactory thingFactory)
      {
          this.thingFactory= thingFactory;
      }
  
      public void Execute(MyDto myDto)
      {
         //do stuff
        //get the next approiate IThing out of the factory and execute
      }
  
      public bool IsApplicable(ThingType thingType)
      {
          return thingType == ThingType.ThingOne;
      }
  </code></pre>
  
  <p>}</p>
  
  <p>my registration for this is </p>
  
  <pre><code>  container.RegisterAll&lt;IThing&gt;(
              from tp in typeof (IThing).Assembly.GetExportedTypes()
              where !tp.IsAbstract
              where typeof (IThing).IsAssignableFrom(tp)
              select tp);
  
     container.Register&lt;IThingFactory , ThingFactory&gt;();
  </code></pre>
  
  <p>This works absolutely fine and I can verify the container without exceptions. 
  However when I also add the following registration to the container I get an exception</p>
  
  <pre><code> container.RegisterDecorator(typeof(ICommandHandler&lt;,&gt;),    
   typeof(UnitOfWorkDecorator&lt;,&gt;));
  </code></pre>
  
  <p>The decorator is a Nhibernate UnitOFWork which manages an Nhibernate transaction(not that this matters)(which following this pattern <a href="https://cuttingedge.it/blogs/steven/pivot/entry.php?id=91" rel="nofollow">https://cuttingedge.it/blogs/steven/pivot/entry.php?id=91</a>)</p>
  
  <pre><code>  public class UnitOfWorkDecorator&lt;TCommand, TResult&gt;
      : ICommandHandler&lt;TCommand, TResult&gt; 
      where TCommand : ICommand
  {
  
      public UnitOfWorkDecorator(
          ICommandHandler&lt;TCommand, TResult&gt; decoratedCommandHandler)
      {
          this.currentSessionContextService = currentSessionContextService;
          this.decoratedCommandHandler = decoratedCommandHandler;
      }
  
      public void Handle(TCommand command)
      {
            //start my nhibernate transaction
            decoratedCommandHandler.Handle(command);
  
            //commit the transaction                       
      }
  </code></pre>
  
  <p>So anyway, when I add the decorator, I get the following exception. when I call</p>
  
  <pre><code>  container.Verify();
  </code></pre>
  
  <p>Yet when I removed the decorator registration all is fine again.</p>
  
  <pre><code>Topshelf v3.1.107.0, .NET Framework v4.0.30319.18052
  Topshelf.Hosts.ConsoleRunHost Error: 0 : An exception occurred, System.Reflectio
  n.TargetInvocationException: Exception has been thrown by the target of an invoc
  ation. ---&gt; System.InvalidOperationException: The configuration is invalid. Crea
  ting the instance for type IThingManager failed. The registered delegate for t
  ype IThingManager threw an exception. The registered delegate for type IThingFa
  ctory threw an exception. The registered delegate for type IEnumerable&lt;IThing&gt; th
  rew an exception. No registration for type ThingOne could be found a
  nd an implicit registration could not be made.  ---&gt; SimpleInjector.ActivationEx
  ception: The registered delegate for type IThingManager threw an exception. Th
  e registered delegate for type IThingFactory threw an exception. The registered d
  elegate for type IEnumerable&lt;IThing&gt; threw an exception. No registration for type
  ThingOne could be found and an implicit registration could not be m
  ade.  ---&gt; SimpleInjector.ActivationException: The registered delegate for type
  IThingFactory threw an exception. The registered delegate for type IEnumerable&lt;IThing&gt;     
  threw an exception. No registration for type ThingOne could be
  found and an implicit registration could not be made.  ---&gt; SimpleInjector.Activ
  ationException: The registered delegate for type IEnumerable&lt;IThing&gt; threw an exc
  eption. No registration for type ThingOne could be found and an impl
  icit registration could not be made.  ---&gt; SimpleInjector.ActivationException: N
  o registration for type ThingOne could be found and an implicit regi
  stration could not be made.
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>at SimpleInjector.Container.ThrowNotConstructableException(Type concreteType)
  at SimpleInjector.Container.ThrowMissingInstanceProducerException(Type servic
  eType)at SimpleInjector.Container.GetRegistration(Type serviceType, Boolean throwOn
   Failure)   at SimpleInjector.Advanced.ContainerControlledCollection`1.   
   &lt;&gt;c__DisplayClass1
  0.&lt;ToLazyInstanceProducer&gt;b__f()   at System.Lazy`1.CreateValue()
  at System.Lazy`1.LazyInitValue()     at     
  SimpleInjector.Advanced.ContainerControlledCollection`1.&lt;SimpleInjector.Ad
  vanced.IContainerControlledCollection.GetRelationships&gt;b__1(Lazy`1 p)
  at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
  at System.Linq.Enumerable.&lt;SelectManyIterator&gt;d__31`3.MoveNext()
  at System.Linq.Enumerable.&lt;DistinctIterator&gt;d__81`1.MoveNext()
  at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
  at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
  at SimpleInjector.Advanced.ContainerControlledCollection`1.SimpleInjector.Adv
  anced.IContainerControlledCollection.GetRelationships()
  at SimpleInjector.Extensions.Decorators.DecoratorHelpers.ContainerControlledC
  ollectionRegistration.GetRelationshipsCore()
  at SimpleInjector.Registration.GetRelationships()
  at SimpleInjector.InstanceProducer.GetRelationships()
  at SimpleInjector.Container.OnExpressionBuilt(ExpressionBuiltEventArgs e, Ins
  tanceProducer instanceProducer)
  at SimpleInjector.InstanceProducer.BuildExpressionInternal()
  at System.Lazy`1.CreateValue()
  at System.Lazy`1.LazyInitValue()
  at SimpleInjector.InstanceProducer.BuildExpression()
  --- End of inner exception stack trace ---
  at SimpleInjector.InstanceProducer.BuildExpression()
  at SimpleInjector.Advanced.DefaultConstructorInjectionBehavior.BuildParameter
  Expression(ParameterInfo parameter)
  at SimpleInjector.Registration.BuildParameterExpressionFor(ParameterInfo para
  meter)
  at SimpleInjector.Registration.&lt;BuildNewExpression&gt;b__1a(&lt;&gt;f__AnonymousTypef`
  2 &lt;&gt;h__TransparentIdentifier18)
  at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
  at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
  at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
  at SimpleInjector.Registration.BuildNewExpression(Type serviceType, Type impl
  ementationType)
  at SimpleInjector.Registration.BuildTransientExpression[TService,TImplementat
  ion]()
  at SimpleInjector.Lifestyles.TransientLifestyle.TransientLifestyleRegistratio
  n`2.BuildExpression()
  at SimpleInjector.InstanceProducer.BuildExpressionInternal()
  at System.Lazy`1.CreateValue()
  at System.Lazy`1.LazyInitValue()
  at SimpleInjector.InstanceProducer.BuildExpression()
  --- End of inner exception stack trace ---
  at SimpleInjector.InstanceProducer.BuildExpression()
  at SimpleInjector.Advanced.DefaultConstructorInjectionBehavior.BuildParameter
  Expression(ParameterInfo parameter)
  at SimpleInjector.Registration.BuildParameterExpressionFor(ParameterInfo para
  meter)
  at SimpleInjector.Registration.&lt;BuildNewExpression&gt;b__1a(&lt;&gt;f__AnonymousTypef`
  2 &lt;&gt;h__TransparentIdentifier18)
  at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
  at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
  at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
  at SimpleInjector.Registration.BuildNewExpression(Type serviceType, Type impl
  ementationType)
  at SimpleInjector.Registration.BuildTransientExpression[TService,TImplementat
  ion]()
  at SimpleInjector.Lifestyles.TransientLifestyle.TransientLifestyleRegistratio
  n`2.BuildExpression()
  at SimpleInjector.InstanceProducer.BuildExpressionInternal()
  at System.Lazy`1.CreateValue()
  at System.Lazy`1.LazyInitValue()
  at SimpleInjector.InstanceProducer.BuildInstanceCreator(Object&amp; createdInstan
  ce)
  at SimpleInjector.InstanceProducer.GetInstance()
  --- End of inner exception stack trace ---
  at SimpleInjector.InstanceProducer.GetInstance()
  at SimpleInjector.InstanceProducer.Verify()
  --- End of inner exception stack trace ---
  at SimpleInjector.InstanceProducer.Verify()
  at SimpleInjector.Container.VerifyProducers(InstanceProducer[] producersToVer
  ify)
  at SimpleInjector.Container.ValidateRegistrations()
  at SimpleInjector.Container.Verify()
  </code></pre>
  
  <p>Thanks for your help</p>
  
  <p><strong>Edit - ThingManager is the entry point and  looks like this:</strong></p>
  
  <pre><code>   public class ThingManager : IThingManager
  {
      private readonly IThingFactory thingFactory;
  
      public ThingManager(IThingFactory thingFactory)
      {
          this.thingFactory = thingFactory;
      }
  
      public void Run(MyDto myDto)
      {
          var firstThing = thingFactory.GetThing(ThingType.ThingOne);
          firstThing.Execute(myDto);
      }
  }
  </code></pre>