CustomCommand.cs 662 B

123456789101112131415161718192021222324252627
  1. using Ninject;
  2. using System;
  3. using System.CommandLine;
  4. namespace CustomHostingDemo
  5. {
  6. public class CustomCommand<TArg> : Command
  7. {
  8. private readonly Type _handlerType;
  9. public CustomCommand(string name, string description, Type handler)
  10. : base(name, description)
  11. {
  12. _handlerType = handler;
  13. }
  14. public Command Bind(IKernel kernel)
  15. {
  16. kernel.Bind<TArg>().ToSelf().InTransientScope();
  17. kernel.Bind(_handlerType).ToSelf().InTransientScope();
  18. Handler = new NinjectCommandHandler<TArg>(kernel, _handlerType);
  19. return this;
  20. }
  21. }
  22. }