|
@@ -2,7 +2,12 @@
|
|
|
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.Binding;
|
|
|
|
|
+using System.CommandLine.Builder;
|
|
|
|
|
+using System.CommandLine.Parsing;
|
|
|
using System.IO;
|
|
using System.IO;
|
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
|
|
|
|
|
@@ -17,6 +22,7 @@ namespace CustomHostingDemo
|
|
|
var config = new ConfigurationBuilder()
|
|
var config = new ConfigurationBuilder()
|
|
|
.SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
|
|
.SetBasePath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
|
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
|
|
|
|
+ .AddJsonFile(Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "custom-demo.json"), optional: true, reloadOnChange: false)
|
|
|
.Build();
|
|
.Build();
|
|
|
|
|
|
|
|
kernel.Bind<IConfiguration>().ToConstant(config).InSingletonScope();
|
|
kernel.Bind<IConfiguration>().ToConstant(config).InSingletonScope();
|
|
@@ -29,6 +35,32 @@ namespace CustomHostingDemo
|
|
|
var logger = kernel.Get<Logger<Program>>();
|
|
var logger = kernel.Get<Logger<Program>>();
|
|
|
logger.LogInformation("Informational Message");
|
|
logger.LogInformation("Informational Message");
|
|
|
logger.LogWarning("Ooopsie!");
|
|
logger.LogWarning("Ooopsie!");
|
|
|
|
|
+
|
|
|
|
|
+ var rootCommand = new RootCommand()
|
|
|
|
|
+ {
|
|
|
|
|
+ new HelloCommand(),
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ var parser = new CommandLineBuilder(rootCommand)
|
|
|
|
|
+ .UseMiddleware((invocationContext) =>
|
|
|
|
|
+ {
|
|
|
|
|
+ //invocationContext.BindingContext.ParseResult.
|
|
|
|
|
+ //invocationContext.BindingContext.AddService(typeof(IResolutionRoot), () => kernel);
|
|
|
|
|
+ invocationContext.BindingContext.AddService(typeof(HelloCommand.DefaultHandler), () =>
|
|
|
|
|
+ {
|
|
|
|
|
+ var handler = kernel.Get<HelloCommand.DefaultHandler>();
|
|
|
|
|
+ var binder = new ModelBinder<HelloCommand.DefaultHandler>();
|
|
|
|
|
+ binder.UpdateInstance(handler, invocationContext.BindingContext);
|
|
|
|
|
+ return handler;
|
|
|
|
|
+ });
|
|
|
|
|
+ //invocationContext.BindingContext.AddService(typeof(HelloCommand), () => {
|
|
|
|
|
+ // return kernel.Get<HelloCommand>();
|
|
|
|
|
+ //});
|
|
|
|
|
+ })
|
|
|
|
|
+ .Build();
|
|
|
|
|
+
|
|
|
|
|
+ parser.InvokeAsync(args);
|
|
|
|
|
+ //rootCommand.Invoke(args);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|