Skip to content

Commit

Permalink
Fix bug where collection was changed while enumerated
Browse files Browse the repository at this point in the history
  • Loading branch information
khellang committed May 1, 2017
1 parent 27e1760 commit 5fc93ce
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Scrutor/ServiceCollectionExtensions.Decoration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ IServiceCollection Decorate(IServiceCollection s, Type[] typeArguments)
return s.DecorateDescriptors(closedServiceType, x => x.Decorate(closedDecoratorType));
}

return services
var arguments = services
.Where(descriptor => descriptor.ServiceType.IsAssignableTo(serviceType))
.Select(descriptor => descriptor.ServiceType.GenericTypeArguments)
.Aggregate(services, Decorate);
.ToArray();

return arguments.Aggregate(services, Decorate);
}

private static IServiceCollection DecorateDescriptors(this IServiceCollection services, Type serviceType, Func<ServiceDescriptor, ServiceDescriptor> decorator)
Expand Down

0 comments on commit 5fc93ce

Please sign in to comment.