-
-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It is not possible to inject IEnumerable<CommandOption> using Microsoft.Extensions.DependencyInjection #85
Comments
If I understand right, you're trying to inject a constructor like this?
If so, yeah, I see the problem. It's here CommandLineUtils/src/CommandLineUtils/CommandLineApplication.cs Lines 925 to 942 in 59f11a6
IEnumerable behavior is not possible to disable in Microsoft.Extensions.DependencyInjection, I don't think it should be a problem to put IEnumerable<CommandOptions> first, before resolving additional services.
|
Yes, that is exactly it. I didn't try it, but I assume it would happen with |
This is an easy fix. I'm hoping to release 2.2.1 later this week, and this will be part of it. |
Fixed in 2.2.1 which is now on nuget.org |
Great, thanks! |
I am trying out the new dependency injection support for models. For
additionalServices
, I am passing anIServiceProvider
created usingServiceCollection.BuildServiceProvider()
inMicrosoft.Extensions.DependencyInjection
.It seems that this service provider always returns an empty enumerable even if there are no implementations of a given service. I suppose this is by design due to the ability to retrieve all implementations of a given service. Since additional services are consulted before getting to the case where
IEnumerable<CommandOption>
is injected usingGetOptions()
in the custom CommandLineUtils service provider, these options can't be injected.The text was updated successfully, but these errors were encountered: