Cysharp / ConsoleAppFramework

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

Feature request: Separate package from ConsoleAppFramework.Host #127

Closed pomianowski closed 4 months ago

pomianowski commented 5 months 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 4 months 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.