Hosting
Nullean.Argh.Hosting plugs the same command registration model into IHost and Microsoft.Extensions.DependencyInjection. No custom bootstrapping or glue code needed.
<ItemGroup>
<PackageReference Include="Nullean.Argh.Hosting" />
</ItemGroup>
services.AddArgh(args, b => { … }) mirrors the same Map / Map<T> / UseGlobalOptions / UseNamespaceOptions / UseMiddleware / MapNamespace surface as ArghApp, and additionally lets you control DI lifetimes.
using Microsoft.Extensions.Hosting;
using Nullean.Argh.Hosting;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddArgh(args, b =>
{
b.Map("hello", MyHandlers.SayHello);
});
await builder.Build().RunAsync();
Important
AddArgh registers a hosted service that runs ArghRuntime.RunAsync(args) and then calls Environment.Exit with the exit code. The host does not continue after the CLI completes.
CancellationTokenon command handlers is linked to both Ctrl+C andIHostApplicationLifetime.ApplicationStopping.- Register
AddArghbefore otherIHostedServiceregistrations if you want the CLI to run first and exit without starting later background work.
- Dependency injection - DI lifetimes and service resolution
- Intrinsic commands - log suppression and fast-path for built-in commands