Skip to content

Commit 38a2d88

Browse files
committed
Attempting to resolve handler instance using serviceProvider
1 parent a3a6b2c commit 38a2d88

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/System.CommandLine/Invocation/ModelBindingCommandHandler.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ public async Task<int> InvokeAsync(InvocationContext context)
6565
object result;
6666
if (_handlerDelegate is null)
6767
{
68-
var invocationTarget = _invocationTarget ??
69-
_invocationTargetBinder?.CreateInstance(bindingContext);
68+
var invocationTarget = _invocationTarget ??
69+
bindingContext.ServiceProvider.GetService(_handlerMethodInfo!.DeclaringType);
70+
if(!(invocationTarget is null))
71+
{
72+
_invocationTargetBinder?.UpdateInstance(invocationTarget, bindingContext);
73+
}
74+
75+
invocationTarget ??= _invocationTargetBinder?.CreateInstance(bindingContext);
7076
result = _handlerMethodInfo!.Invoke(invocationTarget, invocationArguments);
7177
}
7278
else

0 commit comments

Comments
 (0)