EasyConsoleFramework.Base 0.2.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasyConsoleFramework.Base --version 0.2.3
                    
NuGet\Install-Package EasyConsoleFramework.Base -Version 0.2.3
                    
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="EasyConsoleFramework.Base" Version="0.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyConsoleFramework.Base" Version="0.2.3" />
                    
Directory.Packages.props
<PackageReference Include="EasyConsoleFramework.Base" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EasyConsoleFramework.Base --version 0.2.3
                    
#r "nuget: EasyConsoleFramework.Base, 0.2.3"
                    
#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.
#:package EasyConsoleFramework.Base@0.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EasyConsoleFramework.Base&version=0.2.3
                    
Install as a Cake Addin
#tool nuget:?package=EasyConsoleFramework.Base&version=0.2.3
                    
Install as a Cake Tool

Easy Console Framework NuGet NuGet

.NET Core library for easy building console application with command line parsing and inversion of control (IoC).

By default it's using Microsoft.Extensions.DependencyInjection.
To use Autofac please refer to Using Autofac.
To use this with custom IoC please refer to Using custom IoC

It was designed for easy building application with multiple commands and low coupling.

Currently only works on Windows due to shell32.dll dependency.

How to use

  1. Install nuget package ECF
  2. Put in your program.cs this fragment:
// Program.cs
using ECF;

new ECFHostBuilder()
    .UseDefaultCommands() // register all commands with CommandAttribute and default commands (help, exit, ...)
    .AddConfiguration(optional: true) // adds appsettings.json        
    .Configure((ctx, services, _) =>
    {
        ctx.Intro = $"This is example console application based on ECF. Version {typeof(Program).Assembly.GetName().Version}.\nType help to list available commands";
        ctx.HelpIntro = "Welcome to example program that showcases ECF framework. Enter one of command listed below";
        ctx.Prefix = ">";
    })
    .Run(args);

it will initialize and run your ECF console application

  1. You can now add your first command
using ECF;

[Command("hello-world")]
class HelloWorldCommand : CommandBase
{
    private readonly IConfiguration configuration;

    [Parameter(ShortName = "n", LongName = "name", Description = "Your name")]
    public string Name { get; set; }

    public HelloWorldCommand(IConfiguration configuration)
    {
        // you can use constructor to inject services
        this.configuration = configuration;
    }

    public override void Execute()
    {
        if (Name == null)
        {
            DisplayHelp();
            return;
        }

        Console.WriteLine($"Hello {Name}");
    }
}
  1. Run your program you should see welcome info
This is example console application based on ECF. Version 0.1.0.
Type help to list available commands
  1. Invoke your command in console by typing
> hello-world -n John

Template

You can use ECF template to create new projects. Firstly you need to install template:

dotnet new install ECFTemplates

Then you can create new projects using

dotnet new ecf -o MyNewProject

Custom commands

By default it will initialize all commands inside current and entry assembly with [Command] attribute. To change that you can register commands by calling RegisterCommands(params Assembly[]) method:

.Configure((ctx, services, registry) =>
{
    // ...
    registry.RegisterCommands<MyCommandAttribute>(typeof(Class).Assembly);
})

To remove default commands such as help, exit, and load-script you need to remove this line: .UseDefaultCommands()

and register commands manually:

.Configure((ctx, services, registry) =>
{
    // ...
    registry.RegisterCommands<ECF.CommandAttribute>(System.Reflection.Assembly.GetExecutingAssembly());
})

Using Autofac

To use ECF with Autofac install EasyConsoleFramwork.Autofac package. Startup code look very similar with only namespace change:

// Program.cs
using ECF.Autofac;

new ECFHostBuilder()
    .UseDefaultCommands() // register all commands with CommandAttribute and default commands (help, exit, ...)
    .AddConfiguration(optional: true) // adds appsettings.json        
    .Configure((ctx, containerBuilder, _) =>
    {
        ctx.Intro = $"This is example console application based on ECF. Version {typeof(Program).Assembly.GetName().Version}.\nType help to list available commands";
        ctx.HelpIntro = "Welcome to example program that showcases ECF framework. Enter one of command listed below";
        ctx.Prefix = ">";
    })
    .Run(args);

Using custom IoC

To configure ECF with custom IoC follow this steps:

  1. Install nuget package EasyConsoleFramwork.Base
  2. Implement IoC adapters
    • IIoCBuilderAdapter - adapter for interacting with IoC when building (similar to IServiceCollection)
    • IIoCProviderAdapter - adapter for resolving dependencies (similar to IServiceProvider)
    • IIoCScopeAdapter - adapter for scopes, it's implementing IDisposable interface to dispose scope after it ends
  3. Create ECFHostBuilderBase with your IIoCBuilderAdapter implementation
  4. Other steps are similar to normal ECF application

Then you can create new projects using

dotnet new ecf -o MyNewProject
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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on EasyConsoleFramework.Base:

Package Downloads
ECF

Easy Console Framewok - Framework for building command based IoC console application. This package is using Microsoft.Extensions.DependencyInjection library for IoC

EasyConsoleFramework.AutoFac

Easy Console Framewok - Framework for building command based IoC console application. This package is using AutoFac library for IoC.

EasyConsoleFramework.HostedServices

Hosted Services plugin for Easy Console Framewok (ECF).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 380 3/29/2025
1.0.6 225 12/21/2024
1.0.5 177 12/21/2024
1.0.4 177 12/21/2024
1.0.3 257 10/15/2024
1.0.2 216 8/29/2024
1.0.1 220 8/13/2024
1.0.0 153 8/4/2024
0.2.3 195 7/28/2024
0.2.2 149 7/28/2024
0.2.0 266 8/29/2023