Cysharp / ConsoleAppFramework

Zero Dependency, Zero Overhead, Zero Reflection, Zero Allocation, AOT Safe CLI Framework powered by C# Source Generator.
MIT License
1.54k stars 88 forks source link

Feature request: Separate package from ConsoleAppFramework.Host #127

Closed pomianowski closed 1 week ago

pomianowski commented 2 weeks ago

Proposal

Create a simple builder pattern in a separate package to make building a console application using DI easier.

Sample

// ConsoleAppFramework.Host / ConsoleAppFramework.DependencyInjection
ConsoleAppHostBuilder builder = ConsoleApp.CreateHostBuilder(args);
builder.Services.AddSingleton<DbContext>();
builder.Services.AddStackExchangeRedisCache();
builder.Configuration["OpenTelemetryServiceOptions:ServiceVersion"] = Assembly.InformationalVersion;

ConsoleApp app = builder.Build();
app.AddCommands<ConsoleCommands>();
await app.StartAsync(args);
neuecc commented 2 weeks ago

I thought about that at first too. However, in terms of the number of lines, it's not much different from inserting it into the ServiceProvider. So I don't really think it's become that much easier. Considering that, I think the drawback of adding a custom type outweighs the benefits.