Skip to content

Commit

Permalink
Fix StandardConstructorScorer so that it does not fails unit test in …
Browse files Browse the repository at this point in the history
…some situations
  • Loading branch information
remogloor committed Jun 11, 2011
1 parent ba2cc7e commit b47ffc0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/Ninject/Selection/Heuristics/StandardConstructorScorer.cs
Expand Up @@ -48,13 +48,10 @@ public int Score(IContext context, ConstructorInjectionDirective directive)
int score = 1;
foreach(ITarget target in directive.Targets)
{
foreach(IParameter parameter in context.Parameters)
if (ParameterExists(context, target))
{
if(string.Equals(target.Name, parameter.Name))
{
score++;
continue;
}
score++;
continue;
}

Type targetType = target.Type;
Expand All @@ -63,12 +60,25 @@ public int Score(IContext context, ConstructorInjectionDirective directive)

if(targetType.IsGenericType && targetType.GetInterfaces().Any(type => type == typeof(IEnumerable)))
targetType = targetType.GetGenericArguments()[0];

if(context.Kernel.GetBindings(targetType).Any())

if (context.Kernel.GetBindings(targetType).Any())
score++;
else
{
score++;
if (score > 0)
{
score += Int32.MinValue;
}
}
}

return score;
}

private static bool ParameterExists(IContext context, ITarget target)
{
return context.Parameters.Any(parameter => string.Equals(target.Name, parameter.Name));
}
}
}

0 comments on commit b47ffc0

Please sign in to comment.