{"id":21428935,"url":"https://github.com/notcoffee418/csharpscriptoperations","last_synced_at":"2026-04-16T04:03:49.059Z","repository":{"id":40848175,"uuid":"320715227","full_name":"NotCoffee418/CSharpScriptOperations","owner":"NotCoffee418","description":"Easy to configure console interface for quick access to your code.","archived":false,"fork":false,"pushed_at":"2024-07-23T07:54:32.000Z","size":70,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-05T22:10:46.878Z","etag":null,"topics":["cli","console","csharp","dotnet","scripting","testing-tools","ui"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NotCoffee418.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-12T00:30:56.000Z","updated_at":"2024-07-23T07:54:10.000Z","dependencies_parsed_at":"2025-03-16T23:45:32.912Z","dependency_job_id":null,"html_url":"https://github.com/NotCoffee418/CSharpScriptOperations","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NotCoffee418/CSharpScriptOperations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FCSharpScriptOperations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FCSharpScriptOperations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FCSharpScriptOperations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FCSharpScriptOperations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NotCoffee418","download_url":"https://codeload.github.com/NotCoffee418/CSharpScriptOperations/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FCSharpScriptOperations/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31870520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"online","status_checked_at":"2026-04-16T02:00:06.042Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","console","csharp","dotnet","scripting","testing-tools","ui"],"created_at":"2024-11-22T22:15:17.260Z","updated_at":"2026-04-16T04:03:49.019Z","avatar_url":"https://github.com/NotCoffee418.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSharpScriptOperations\n\n[![Nuget](https://img.shields.io/nuget/v/CSharpScriptOperations?style=for-the-badge \"Nuget\")](https://www.nuget.org/packages/CSharpScriptOperations)\n\n## What is it?\nCSharpScriptOperations is a library for .NET console applications to quickly set up a console application interface.  \nDevelopers can use it to get quick access to specific portions of their codebase by creating an `IOperation` for it.\nThis library optionally supports dependency injection through Autofac.\n\n## Quick Start\nCreate an operation in a new class implementing `IOperation` with an `OperationDescription` attribute.\n```csharp\n[OperationDescription(\"Print the result of 2+2\")]\nclass TwoPlusTwo : IOperation\n{\n    public async Task RunAsync()\n    {\n        int result = 2 + 2;\n        Console.WriteLine($\"2 + 2 = {result}\");\n    }\n}\n```\nRegister your operations in `Program.cs`.\n```csharp\nOperationManager.AutoRegisterOperations();\nawait OperationManager.StartListeningAsync();\n```\n\n## What does it look like?\nThis is an example taken from the [DemoApp](https://github.com/NotCoffee418/CSharpScriptOperations/blob/main/DemoApp).\n```\nAvailable Operations:\n0. Exit Application\n1. Say 'Hello World!'\n2. Print the result of 2+2\n3. Print the current weather in London\n4. Demo UserInput\n5. Multiply with Autofac dependency injection\n6. Legacy Description'\n\nSelect an operation ('help' for list of operations)\n1\n\nRunning operation 1...\nHello World!\n```\n\n## Detailed Instructions\n### 1. Install the nuget package.\nInstall the  [nuget package](https://www.nuget.org/packages/CSharpScriptOperations/) into a **Console Application**.  \nCall `using CSharpScriptOperations` wherever you need it.\n\n### 2. Create operations\nOperations are class objects dedicated to a specific task or set of tasks. They implement this package's `IOperation` class.  \nAn operation will look something like this:\n```csharp\n\n[OperationDescription(\"Print the result of 2+2\")]\nclass TwoPlusTwo : IOperation\n{\n    public async Task RunAsync()\n    {\n        int result = 2 + 2;\n        Console.WriteLine($\"2 + 2 = {result}\");\n    }\n}\n```\nWhatever is in the `RunAsync()` method is called when the operation is requested.  \nThe description attribute is used in the console to show what the operation does.\n\n### 3. Register your operations\nBulk register your operations in one swoop:\n\n### Automatic Registration\n```csharp\nOperationManager.AutoRegisterOperations()\n```\n\n#### Manual registration\n```csharp\nOperationManager.RegisterOperationsBulk(\n    new List\u003cType\u003e() {\n        typeof(TwoPlusTwo),\n        typeof(LondonWeather),\n    }\n);\n```\n\nOr register operations one by one:\n```csharp\nOperationManager.RegisterOperation(typeof(HelloWorld));\n```\n\n### 4. Register dependencies (optional)\nYou can optionally use dependency injection with Autofac or Microsoft Dependency Injection.\n\n\nRegister any dependencies to `OperationManager.ContainerBuilder` before starting the listener.\n```csharp\nContainerBuilder AutofacContainerBuilder = new ContainerBuilder();\n\n// Include application dependencies\nOperationManager.ContainerBuilder\n    .RegisterType\u003cExampleDependency\u003e()\n    .As\u003cIExampleDependency\u003e();\n\n// Include the services registered by the OperationManager\nAutofacContainerBuilder.Populate(OperationManager.Services);\n\n// Build the container\nvar serviceProvider = new AutofacServiceProvider(AutofacContainerBuilder.Build());\n```\n\n### 5. Start the listener\nThis will display our options and interpret user input to run the approperiate operation.\n```csharp\nawait OperationManager.StartListeningAsync();\n\n// or if you use dependency injection\nawait OperationManager.StartListeningAsync(serviceProvider);\n```\nAlternatively you can implement your own version of `StartListening()`.  \nYou can access the registered operations and it's classes through the\n`OperationManager.RegisteredOperations` object.\n\n### 6. Try it out\nThe output of the ExampleConsoleApp looks like this:\n```\nAvailable Operations:\n0. Exit Application\n1. Print the result of 2+2\n2. Print the current weather in London\n3. Say 'Hello World!'\n\nSelect an operation ('help' for list of operations)\n```\nAnd we can run the operations by entering the requested operation's number.\n```\nSelect an operation ('help' for list of operations)\n2\n\nRunning operation 2: Print the current weather in London...\nThe weather in London is currently: Light Rain\nOperation complete (or running in the background)\n```\nThe application will run until operation 0 is called.  \nThe `0. Exit Application` operation is already installed by default.\n\n### Example\n\nSee the full implementation examples in the [DemoApp](https://github.com/NotCoffee418/CSharpScriptOperations/blob/main/DemoApp).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotcoffee418%2Fcsharpscriptoperations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotcoffee418%2Fcsharpscriptoperations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotcoffee418%2Fcsharpscriptoperations/lists"}