Created
December 29, 2021 17:11
-
-
Save neuecc/a503e34d92611710f7affc65957b47a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // You can use full feature of Generic Host(same as ASP.NET Core). | |
| var builder = ConsoleApp.CreateBuilder(args); | |
| builder.ConfigureServices((ctx,services) => | |
| { | |
| // Register EntityFramework database context | |
| services.AddDbContext<MyDbContext>(); | |
| // Register appconfig.json to IOption<MyConfig> | |
| services.Configure<MyConfig>(ctx.Configuration); | |
| }); | |
| var app = builder.Build(); | |
| // setup many command, async, short-name/description option, subcommand, DI | |
| app.AddCommand("calc-sum", (int x, int y) => Console.WriteLine(x + y)); | |
| app.AddCommand("sleep", async ([Option("t", "seconds of sleep time.")] int time) => | |
| { | |
| await Task.Delay(TimeSpan.FromSeconds(time)); | |
| }); | |
| app.AddSubCommand("verb", "childverb", () => Console.WriteLine("called via 'verb childverb'")); | |
| // You can insert all public methods as sub command. | |
| app.AddSubCommands<DatabaseApp>(); | |
| app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment