Skip to content

Commit 2a5ef58

Browse files
support default parameter values
1 parent 4abe129 commit 2a5ef58

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Ninject.Web.AspNetCore/Planning/ParameterTargetWithKeyedSupport.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ private object ResolveFromKeyedService(IContext parent, FromKeyedServicesAttribu
7474
}
7575
catch (ActivationException ex)
7676
{
77+
if (Site.HasDefaultValue)
78+
{
79+
// in case we have a default value for the constructor parameter, we don't throw but use the default instead.
80+
return Site.DefaultValue;
81+
}
7782
throw new InvalidOperationException(
7883
$"Can't resolve keyed service of Type {Type} with key {fromKeyedServiceValue}", ex);
7984
}

0 commit comments

Comments
 (0)