|
@@ -7,8 +7,10 @@ using System;
|
|
|
using System.CommandLine;
|
|
using System.CommandLine;
|
|
|
using System.CommandLine.Binding;
|
|
using System.CommandLine.Binding;
|
|
|
using System.CommandLine.Builder;
|
|
using System.CommandLine.Builder;
|
|
|
|
|
+using System.CommandLine.Invocation;
|
|
|
using System.CommandLine.Parsing;
|
|
using System.CommandLine.Parsing;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
|
|
+using System.Linq;
|
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
namespace CustomHostingDemo
|
|
namespace CustomHostingDemo
|
|
@@ -29,6 +31,18 @@ namespace CustomHostingDemo
|
|
|
kernel.Bind<ILoggerFactory>().To<LoggerFactory>().InSingletonScope();
|
|
kernel.Bind<ILoggerFactory>().To<LoggerFactory>().InSingletonScope();
|
|
|
kernel.Bind(typeof(Logger<>)).ToSelf().InSingletonScope();
|
|
kernel.Bind(typeof(Logger<>)).ToSelf().InSingletonScope();
|
|
|
kernel.Bind<ILoggerProvider>().To<LoggerProvider>().InSingletonScope();
|
|
kernel.Bind<ILoggerProvider>().To<LoggerProvider>().InSingletonScope();
|
|
|
|
|
+ kernel.Bind<ILog>().To<Log>().InTransientScope();
|
|
|
|
|
+
|
|
|
|
|
+ kernel.Bind<InvocationContext>().ToMethod(ctx =>
|
|
|
|
|
+ {
|
|
|
|
|
+ var parameter = ctx.Parameters.FirstOrDefault(p => p.Name == nameof(InvocationContext));
|
|
|
|
|
+ if (parameter == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ throw new Exception("Cannot resolve InvocationContext outside of an actual NinjectCommandHandler invocation");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return (InvocationContext)parameter.GetValue(ctx, null);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
Console.WriteLine($"Hello {config["Hello"]}");
|
|
Console.WriteLine($"Hello {config["Hello"]}");
|
|
|
|
|
|