dotnet / dotnet/command-line-api
Hosting: Custom Model Binding not used, not found in service collection
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
I am using the commandline hosting and added
a custom model binder like shown here
https://github.com/dotnet/command-line-api/blob/be7ff040e53022fa6730dc30ea511f7bdd97f3f9/src/System.CommandLine.Tests/Binding/ModelBinderTests.cs#L661-L668
but the model binder is not used, as the logic tries to find the binder in the service collection, but it was not added before:
https://github.com/dotnet/command-line-api/blob/be7ff040e53022fa6730dc30ea511f7bdd97f3f9/src/System.CommandLine.Hosting/HostingExtensions.cs#L77-L81
when manually adding the model binder to service collection it gets used.
Is this the expected behavior to manually add the model binder to service collection or should it be enough when adding the model binder to the `BindingContext`?
P.S. in a non dependency injection context the custom model binder works as expected.
Contributor guide
Assessment
This issue has not been assessed yet.