|
@@ -2,15 +2,11 @@
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
|
using Ninject;
|
|
using Ninject;
|
|
|
-using Ninject.Syntax;
|
|
|
|
|
using System;
|
|
using System;
|
|
|
using System.CommandLine;
|
|
using System.CommandLine;
|
|
|
-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
|
|
@@ -19,7 +15,10 @@ namespace CustomHostingDemo
|
|
|
{
|
|
{
|
|
|
static int Main(string[] args)
|
|
static int Main(string[] args)
|
|
|
{
|
|
{
|
|
|
- var kernel = new StandardKernel();
|
|
|
|
|
|
|
+ var kernel = new StandardKernel(
|
|
|
|
|
+ new LoggingModule(),
|
|
|
|
|
+ new CommandHandlerModule()
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
var config = new ConfigurationBuilder()
|
|
var config = new ConfigurationBuilder()
|
|
|
.SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
|
|
.SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
|
|
@@ -28,26 +27,9 @@ namespace CustomHostingDemo
|
|
|
.Build();
|
|
.Build();
|
|
|
|
|
|
|
|
kernel.Bind<IConfiguration>().ToConstant(config).InSingletonScope();
|
|
kernel.Bind<IConfiguration>().ToConstant(config).InSingletonScope();
|
|
|
- kernel.Bind<ILoggerFactory>().To<LoggerFactory>().InSingletonScope();
|
|
|
|
|
- kernel.Bind(typeof(Logger<>)).ToSelf().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"]}");
|
|
|
|
|
|
|
|
|
|
var logger = kernel.Get<Logger<Program>>();
|
|
var logger = kernel.Get<Logger<Program>>();
|
|
|
- logger.LogInformation("Informational Message");
|
|
|
|
|
|
|
+ logger.LogInformation($"Informational Message - Hello {config["Hello"]}");
|
|
|
logger.LogWarning("Ooopsie!");
|
|
logger.LogWarning("Ooopsie!");
|
|
|
|
|
|
|
|
var rootCommand = new RootCommand()
|
|
var rootCommand = new RootCommand()
|
|
@@ -56,21 +38,6 @@ namespace CustomHostingDemo
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
var parser = new CommandLineBuilder(rootCommand)
|
|
var parser = new CommandLineBuilder(rootCommand)
|
|
|
- //.UseMiddleware((invocationContext) =>
|
|
|
|
|
- //{
|
|
|
|
|
- // var cmdArgs = new HelloCommand.HelloArgs();
|
|
|
|
|
- // var binder = new ModelBinder<HelloCommand.HelloArgs>();
|
|
|
|
|
- // binder.UpdateInstance(cmdArgs, invocationContext.BindingContext);
|
|
|
|
|
-
|
|
|
|
|
- // kernel.Bind<HelloCommand.HelloArgs>().ToConstant(cmdArgs).InSingletonScope();
|
|
|
|
|
-
|
|
|
|
|
- // //invocationContext.BindingContext.AddService(typeof(HelloCommand.HelloArgs), () => cmdArgs);
|
|
|
|
|
- // invocationContext.BindingContext.AddService(typeof(HelloCommand.DefaultHandler), () =>
|
|
|
|
|
- // {
|
|
|
|
|
- // var handler = kernel.Get<HelloCommand.DefaultHandler>();
|
|
|
|
|
- // return handler;
|
|
|
|
|
- // });
|
|
|
|
|
- //})
|
|
|
|
|
.UseDefaults()
|
|
.UseDefaults()
|
|
|
.Build();
|
|
.Build();
|
|
|
|
|
|