Skip to content

Commit

Permalink
Fixed #237
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-xu committed Sep 17, 2017
1 parent 83f5714 commit 4f5a384
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Version 4.0
- Bugfix: Break Singleton / circular dependency WithPropertyValue
- Bugfix: InSingletonScope bug when requesting an instance in OnActivation callback https://github.com/ninject/Ninject/issues/221 https://github.com/ninject/Ninject/issues/224
- Bugfix: The invoked member is not supported in a dynamic assembly https://github.com/ninject/Ninject/issues/225
- Bugfix: Conditional binding is not being considered when score constructors https://github.com/ninject/Ninject/issues/237

Version 3.2
---------------
Expand Down
13 changes: 13 additions & 0 deletions src/Ninject.Test/Integration/ConstructorSelectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ public void FirstAvailableWithBindingAvailableIsUsed()
barracks.Weapon.Should().NotBeNull();
}

[Fact]
public void UnsatisfiedConditionalShouldBeIngored()
{
kernel.Bind<Barracks>().ToSelf();
kernel.Bind<IWeapon>().To<Sword>();
kernel.Bind<IWarrior>().To<Samurai>().When(_ => false);

var barracks = kernel.Get<Barracks>();
barracks.Should().NotBeNull();
barracks.Warrior.Should().BeNull();
barracks.Weapon.Should().NotBeNull();
}

[Fact]
public void CtorWithMostDependenciesIsUsedWhenBindingsAreAvailable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ protected virtual bool BindingExists(IContext context, ITarget target)
protected virtual bool BindingExists(IReadOnlyKernel kernel, IContext context, ITarget target)
{
var targetType = this.GetTargetType(target);
return kernel.GetBindings(targetType).Any(b => !b.IsImplicit)
var request = context.Request.CreateChild(targetType, context, target);

return kernel.GetBindings(targetType).Any(b => !b.IsImplicit && b.Matches(request))
|| target.HasDefaultValue;
}

Expand Down

0 comments on commit 4f5a384

Please sign in to comment.