autofac/Autofac — pull request #578 by DrunkyBard (2014-09-29 11:23:10+00:00)
Title: - Fix resolving generic class

If you run TheSameaceholderWithThreeGenericParametersTypeCanAppearMultipleTimesInTheService test with FirstOrDefault() call in OpenGenericServiceBinder class TryFindServiceArgumentForImplementationArgumentDefinition method, then test throw exception :
```
The requested service 'Autofac.Tests.Features.OpenGenerics.ComplexGenericsTests+IDouble`2[[Autofac.Tests.Features.OpenGenerics.ComplexGenericsTests+INested`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], Autofac.Tests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da],
[Autofac.Tests.Features.OpenGenerics.ComplexGenericsTests+INested`1[[Autofac.Tests.Features.OpenGenerics.ComplexGenericsTests+IDouble`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], Autofac.Tests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da]], Autofac.Tests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da]]' has not been registered.
To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
```

StackTrace:
```
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context)
at Autofac.Tests.Features.OpenGenerics.ComplexGenericsTests.TheSameaceholderWithThreeGenericParametersTypeCanAppearMultipleTimesInTheService()
```

But if you change FirstOrDefault() to FirstOrDefault(x => x != null), then test pass successful.
In TryFindServiceArgumentForImplementationArgumentDefinition method in OpenGenericServiceBinder class next code return not empty collection with one not null element, but if not null element is not first in the collection, then this method return null:

```
return serviceArgumentDefinitionToArgument
.Where(argdef => argdef.Key.IsGenericType && argdef.Value.GetGenericArguments().Length > 0)
.Select(argdef => TryFindServiceArgumentForImplementationArgumentDefinition(
implementationGenericArgumentDefinition, argdef.Key.GetGenericArguments().Zip(argdef.Value.GetGenericArguments(), (a, b) => new KeyValuePair(a, b))))
.FirstOrDefault();
```