Use top-level statements in demo

This commit is contained in:
Tyrrrz
2021-12-08 23:52:33 +02:00
parent 2feeb21270
commit ef87ff76fc

View File

@@ -1,35 +1,25 @@
using System; using CliFx;
using System.Threading.Tasks;
using CliFx.Demo.Commands; using CliFx.Demo.Commands;
using CliFx.Demo.Domain; using CliFx.Demo.Domain;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace CliFx.Demo; // We use Microsoft.Extensions.DependencyInjection for injecting dependencies in commands
var services = new ServiceCollection();
public static class Program // Register services
{ services.AddSingleton<LibraryProvider>();
private static IServiceProvider GetServiceProvider()
{
// We use Microsoft.Extensions.DependencyInjection for injecting dependencies in commands
var services = new ServiceCollection();
// Register services // Register commands
services.AddSingleton<LibraryProvider>(); services.AddTransient<BookCommand>();
services.AddTransient<BookAddCommand>();
services.AddTransient<BookRemoveCommand>();
services.AddTransient<BookListCommand>();
// Register commands var serviceProvider = services.BuildServiceProvider();
services.AddTransient<BookCommand>();
services.AddTransient<BookAddCommand>();
services.AddTransient<BookRemoveCommand>();
services.AddTransient<BookListCommand>();
return services.BuildServiceProvider(); return await new CliApplicationBuilder()
} .SetDescription("Demo application showcasing CliFx features.")
.AddCommandsFromThisAssembly()
public static async Task<int> Main() => .UseTypeActivator(serviceProvider.GetRequiredService)
await new CliApplicationBuilder() .Build()
.SetDescription("Demo application showcasing CliFx features.") .RunAsync();
.AddCommandsFromThisAssembly()
.UseTypeActivator(GetServiceProvider().GetRequiredService)
.Build()
.RunAsync();
}