mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Use top-level statements in demo
This commit is contained in:
@@ -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();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user