-
-
Notifications
You must be signed in to change notification settings - Fork 254
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
Example of how to define commands that require components to be injected #43
Comments
To clarify myself: I ended up creating a weird closure to perform injection in the form of:
This resolves dependency injection but obviously requires too much boilerplate to wire up simple things. AND prevents me from using declarative API syntax |
I haven't currently created a way to do this. The current requirement for But, if I were to do this, I would favor constructor injection and add an overload like class Program
{
public static int Main(string[] args)
{
System.IServiceProvider container = CreateServiceContainer();
return CommandLineApplication.Execute<App>(container, args);
}
static System.IServiceProvider CreateServiceContainer()
{
// ...
}
}
class App
{
public App(ManifestCommand command,IContainer container, ILogger logger)
{ }
[Argument(0)]
public int Number { get; }
} |
@natemcmaster btw, the DI sample in this site works correctly. |
I've added support for this. See the sample I wrote here: https://github.com/natemcmaster/CommandLineUtils/blob/cc4d6015bb91eb16f2cb2bb867b858fe0f979d8c/samples/Conventions/DependencyInjection.cs This will be out in 2.2.0-beta, or you can try the nightly builds (see README). Give it a shot and let me know if it works for you. |
hi @natemcmaster ,
I am struggling to find an example of how it is envisioned to define commands that accept custom dependencies injected using declarative syntax.
Is there any place where you could point me to see an example of how to do this?
The text was updated successfully, but these errors were encountered: