From 9d029930bb833ade81c91dc1cad0bfdd39a561a5 Mon Sep 17 00:00:00 2001 From: Scott Xu Date: Fri, 16 Feb 2018 23:36:53 +0800 Subject: [PATCH] Fixed https://github.com/ninject/Ninject/issues/263 (#264) --- ...ceRequestsUnconstrainedEnumerableOfDependencies.cs | 11 ++++++++++- src/Ninject/KernelBase.cs | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Ninject.Test/Integration/EnumerableDependenciesTests/WhenServiceRequestsUnconstrainedEnumerableOfDependencies.cs b/src/Ninject.Test/Integration/EnumerableDependenciesTests/WhenServiceRequestsUnconstrainedEnumerableOfDependencies.cs index 018fa200..a1d455f5 100644 --- a/src/Ninject.Test/Integration/EnumerableDependenciesTests/WhenServiceRequestsUnconstrainedEnumerableOfDependencies.cs +++ b/src/Ninject.Test/Integration/EnumerableDependenciesTests/WhenServiceRequestsUnconstrainedEnumerableOfDependencies.cs @@ -48,5 +48,14 @@ public void EmptyEnumerableIsResolvedIfElementTypeIsMissingBinding() children.Should().BeEmpty(); } + + [Fact] + public void EmptyEnumerableIsResolvedIfElementTypeIsMissingBindingEvenIsWasResoved() + { + var child = this.Kernel.Get(); + var children = this.Kernel.Get>(); + + children.Should().BeEmpty(); + } } -} \ No newline at end of file +} diff --git a/src/Ninject/KernelBase.cs b/src/Ninject/KernelBase.cs index 46e0cc8b..94cb812a 100644 --- a/src/Ninject/KernelBase.cs +++ b/src/Ninject/KernelBase.cs @@ -531,7 +531,7 @@ void UpdateRequest(Type service) { if (handleMissingBindings && this.HandleMissingBinding(request)) { - return this.Resolve(request, false); + return this.Resolve(request); } if (request.IsOptional) @@ -568,7 +568,7 @@ from binding in satisfiedBindings } else { - if (satisfiedBindings.Any(binding => !binding.IsImplicit)) + if (satisfiedBindings.Any(binding => !binding.IsImplicit) || !handleMissingBindings) { satisfiedBindings = satisfiedBindings.Where(binding => !binding.IsImplicit); }