Visium.Anima.Extensions.Console
1.0.0-alpha.16
dotnet add package Visium.Anima.Extensions.Console --version 1.0.0-alpha.16
NuGet\Install-Package Visium.Anima.Extensions.Console -Version 1.0.0-alpha.16
<PackageReference Include="Visium.Anima.Extensions.Console" Version="1.0.0-alpha.16" />
<PackageVersion Include="Visium.Anima.Extensions.Console" Version="1.0.0-alpha.16" />
<PackageReference Include="Visium.Anima.Extensions.Console" />
paket add Visium.Anima.Extensions.Console --version 1.0.0-alpha.16
#r "nuget: Visium.Anima.Extensions.Console, 1.0.0-alpha.16"
#:package Visium.Anima.Extensions.Console@1.0.0-alpha.16
#addin nuget:?package=Visium.Anima.Extensions.Console&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Visium.Anima.Extensions.Console&version=1.0.0-alpha.16&prerelease
Anima.Extensions.Console
Utilities for quickly creating console applications with Microsoft.Extensions.DependencyInjection
.
Usage
The following sections explain how to create a basic console application using this library.
1. Create an application menu
Add console commands to your application by implementing IConsoleCommand
or IAsyncConsoleCommand
into
any classes you like.
public class HelloWorldCommand : IConsoleCommand
{
public string Path => "Print Commands/Print Hello World";
public string Description => "Displays the words \"Hello World\" in the console.";
public void Execute()
{
Console.WriteLine("Hello, World!");
}
}
The above example will add the Print Hello World
command to a menu named Print Commands
, which when selected,
will write Hello, World!
to the console.
2. Set up the application
The following example uses a top-level statements Program.cs
, but this will work with any setup of
console application that has a configurable IServiceCollection
.
First, call the AddAnimaConsole
extension method to add necessary services to the service container.
var services = new ServiceCollection()
.AddAnimaConsole()
.BuildServiceProvider();
Resolve IConsoleApplicationBuilderFactory
from the service provider and create a new builder instance.
var factory = services.GetRequiredService<IConsoleApplicationBuilderFactory>();
var builder = factory.Create();
Build the application. This example adds a red application name title when the app starts, then builds the app instance.
var application = builder
.WithTitle("My Console Application", ConsoleColor.Red)
.Build();
3. Run the application
There are two ways to do this.
await application.RunAsync();
This above will run the application indefinitely, until the user selects the Exit
option from the root application
menu. The exit command is added to the end of the root menu automatically by this library.
Alternatively, the menu can be run through just once before returning control back to the application.
await application.RunOnceAsync();
Once a command is selected, it will be executed, then the application will close if there is nothing after this line.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0-alpha.16 | 113 | 8/18/2025 |
1.0.0-alpha.15 | 135 | 4/24/2025 |