AutomationIoC.Consoles 2.1.0-alpha2

Suggested Alternatives

BlazorFocused.Automation.CommandLine

This is a prerelease version of AutomationIoC.Consoles.
dotnet add package AutomationIoC.Consoles --version 2.1.0-alpha2                
NuGet\Install-Package AutomationIoC.Consoles -Version 2.1.0-alpha2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AutomationIoC.Consoles" Version="2.1.0-alpha2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AutomationIoC.Consoles --version 2.1.0-alpha2                
#r "nuget: AutomationIoC.Consoles, 2.1.0-alpha2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AutomationIoC.Consoles as a Cake Addin
#addin nuget:?package=AutomationIoC.Consoles&version=2.1.0-alpha2&prerelease

// Install AutomationIoC.Consoles as a Cake Tool
#tool nuget:?package=AutomationIoC.Consoles&version=2.1.0-alpha2&prerelease                

Nuget Version Nuget Downloads Continuous Integration

AutomationIoC.Consoles

Dependency Injection Framework for C# Console Applications

Requirements

Getting Started

Installation

dotnet add package AutomationIoC.Consoles

Development

See Sample Project for a full sample solution

Create AutomationIoC Consoles Command to run

public class TestCommand : StandardCommand
{
    public override void ConfigureCommand(IServiceBinderFactory serviceBinderFactory, Command command)
    {
        var greetingOption = new Option<string>(
            name: "--greeting",
            description: "New greeting to display.");

        command.AddOption(greetingOption);

        command.SetHandler(UpdateGreeting,
            greetingOption,
            serviceBinderFactory.Create<ITestService>(),
            serviceBinderFactory.Create<IConfiguration>());
    }

    public override Action<IConfigurationBuilder> ConfigurationBuilder => (configurationBuilder) =>
    {
        var appSettings = new Dictionary<string, string>()
        {
            ["CurrentGreetingMessage"] = "Current Greeting: {0}",
            ["NewGreetingMessage"] = "New Greeting: {0}"
        };
    };

    public override Action<IServiceCollection> Services => (serviceCollection) =>
    {
        serviceCollection.AddScoped<ITestService, TestService>();
    };

    private void UpdateGreeting(
        string newGreeting,
        ITestService testService,
        IConfiguration configuration)
    {
        string unformattedCurrentGreeting = configuration.GetValue<string>("CurrentGreetingMessage");
        string unformattedNewGreeting = configuration.GetValue<string>("NewGreetingMessage");

        string currentGreeting = testService.GetGreeting();

        Console.WriteLine(unformattedCurrentGreeting, currentGreeting);

        string updatedGreeting = testService.UpdateGreeting(newGreeting);

        Console.WriteLine(unformattedNewGreeting, updatedGreeting);
    }
}

Add AutomationIoC Consoles Builder in startup

class Program
{
    static void Main(string[] args)
    {
        IAutomationIoConsoleBuilder builder =
            AutomationIoConsole.CreateDefaultBuilder(args)
                // Add command name/path here
                .AddCommand<TestCommand>("greet");

        IAutomationIoConsole console = builder.Build();

        console.Run();
    }
}

Run command

dotnet run -- greet --greeting "Hello World"

Other Resources

Package Description
AutomationIoC Framework Runtime for AutomationIoC Console Applications and PowerShell Cmdlets
AutomationIoC.PSCmdlets Dependency Injection Framework for C# PowerShell Cmdlets
AutomationIoC.PSCmdlets.Tools Tooling for running/testing C# PowerShell Cmdlets
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.