Skip to content

Commit

Permalink
Resolve using standard binding resolver, before resolving as a collec…
Browse files Browse the repository at this point in the history
…tion.

Fixes ninject#333.
  • Loading branch information
drieseng committed Mar 5, 2019
1 parent 8b47034 commit 3c74b47
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/Ninject.Test/Integration/ConstantTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void SameInstanceShouldBeReturnedWhenConstantIsSingularService()
instance.Should().BeSameAs(sword);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void SameInstanceShouldBeReturnedWhenConstantIsArray()
{
var swords = new Sword[0];
Expand All @@ -43,7 +43,7 @@ public void SameInstanceShouldBeReturnedWhenConstantIsArray()
instance.Should().BeSameAs(swords);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void SameInstanceShouldBeReturnedWhenConstantIsGenericList()
{
var swords = new List<Sword>();
Expand All @@ -53,7 +53,7 @@ public void SameInstanceShouldBeReturnedWhenConstantIsGenericList()
instance.Should().BeSameAs(swords);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void SameInstanceShouldBeReturnedWhenConstantIsGenericICollection()
{
var swords = new List<Sword>();
Expand All @@ -63,7 +63,7 @@ public void SameInstanceShouldBeReturnedWhenConstantIsGenericICollection()
instance.Should().BeSameAs(swords);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void SameInstanceShouldBeReturnedWhenConstantIsGenericIList()
{
var swords = new List<Sword>();
Expand Down
12 changes: 6 additions & 6 deletions src/Ninject.Test/Integration/ReadOnlyKernelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public void TryGetOfT_Parameters()
weapons.Should().HaveCount(2);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void TryGetOfT_Parameters_ShouldPreferBindingForList()
{
Configuration.Bind<IWeapon>().To<Sword>();
Expand Down Expand Up @@ -507,7 +507,7 @@ public void TryGetOfT_NameAndParameters()
bindings.Should().HaveCount(0);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void TryGetOfT_NameAndParameters_ShouldPreferBindingForList()
{
Configuration.Bind<IWeapon>().To<Sword>().Named("a");
Expand Down Expand Up @@ -543,7 +543,7 @@ public void TryGetOfT_ConstraintAndParameters()
bindings.Should().HaveCount(0);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void TryGetOfT_ConstraintAndParameters_ShouldPreferBindingForList()
{
Configuration.Bind<IWeapon>().To<Sword>().Named("a");
Expand Down Expand Up @@ -582,7 +582,7 @@ public void TryGet_ServiceAndParameters()
bindings.Should().HaveCount(0);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void TryGet_ServiceAndParameters_ShouldPreferBindingForList()
{
Configuration.Bind<IWeapon>().To<Sword>();
Expand Down Expand Up @@ -624,7 +624,7 @@ public void TryGet_ServiceAndNameAndParameters()
bindings.Should().HaveCount(0);
}

[Fact(Skip = "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void TryGet_ServiceAndNameAndParameters_ShouldPreferBindingForList()
{
Configuration.Bind<IWeapon>().To<Sword>().Named("a");
Expand Down Expand Up @@ -667,7 +667,7 @@ public void TryGet_ServiceAndConstraintAndParameters()
bindings.Should().HaveCount(0);
}

[Fact(Skip= "https://github.com/ninject/Ninject/issues/333")]
[Fact]
public void TryGet_ServiceAndConstraintAndParameters_ShouldPreferBindingForList()
{
Configuration.Bind<IWeapon>().To<Sword>().Named("a");
Expand Down
24 changes: 12 additions & 12 deletions src/Ninject/ReadOnlyKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,6 @@ private IEnumerable<object> ResolveAll(IRequest request, bool handleMissingBindi

private object ResolveSingleUnique(IRequest request, bool handleMissingBindings)
{
var collection = this.ResolveCollection(request);
if (collection != null)
{
return collection;
}

var bindings = this.GetBindingsCore(request.Service);
IBinding satisfiedBinding = null;

Expand Down Expand Up @@ -455,6 +449,12 @@ private object ResolveSingleUnique(IRequest request, bool handleMissingBindings)
return this.CreateContext(request, satisfiedBinding).Resolve();
}

var collection = this.ResolveCollection(request);
if (collection != null)
{
return collection;
}

if (handleMissingBindings && this.HandleMissingBinding(request))
{
return this.ResolveSingle(request, true);
Expand Down Expand Up @@ -547,12 +547,6 @@ private IEnumerable<object> ResolveAllNonUnique(IRequest request, bool handleMis

private object ResolveSingleNonUnique(IRequest request, bool handleMissingBindings)
{
var collection = this.ResolveCollection(request);
if (collection != null)
{
return collection;
}

var bindings = this.GetBindingsCore(request.Service);
IBinding satisfiedBinding = null;

Expand All @@ -578,6 +572,12 @@ private object ResolveSingleNonUnique(IRequest request, bool handleMissingBindin
return this.CreateContext(request, satisfiedBinding).Resolve();
}

var collection = this.ResolveCollection(request);
if (collection != null)
{
return collection;
}

/*
/ We end up here if there are no bindings for the service, or if there's no binding that satisfies
/ the request.
Expand Down

0 comments on commit 3c74b47

Please sign in to comment.