https://github.com/devlead/devlead.console
An opinionated .NET source package simplifying bootstrapping console applications with IoC, command-line parsing, logging, and more.
https://github.com/devlead/devlead.console
Last synced: 9 months ago
JSON representation
An opinionated .NET source package simplifying bootstrapping console applications with IoC, command-line parsing, logging, and more.
- Host: GitHub
- URL: https://github.com/devlead/devlead.console
- Owner: devlead
- License: mit
- Created: 2024-12-19T08:57:17.000Z (over 1 year ago)
- Default Branch: develop
- Last Pushed: 2025-02-11T06:56:50.000Z (about 1 year ago)
- Last Synced: 2025-02-11T07:32:42.684Z (about 1 year ago)
- Language: C#
- Size: 44.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Devlead.Console
Devlead.Console is a streamlined NuGet source package designed to accelerate the development of .NET console applications. By providing out-of-the-box configurations for Inversion of Control (IoC), command-line parsing, logging, and other essential utilities, Devlead.Console allows developers to focus on building business logic rather than setting up foundational components.
## Features
- Dependency injection / IoC container via Microsoft.Extensions
- Command-line parsing via Spectre.Console
- Logging via Microsoft.Extensions.Logging.Console
- Configuration via Microsoft.Extensions.Configuration
- Source-link for GitHub (or Azure Repos by setting MSBuild property `AzureRepos` to `true`)
- ...
## Installation
```
dotnet add package Devlead.Console
```
## Usage Example
Here's how to create a console application using Devlead.Console, which comes with sensible defaults to streamline your setup. Additionally, you can utilize optional partial methods to tailor the project to your specific needs:
```csharp
public partial class Program
{
// Configure in-memory settings (useful for development/testing)
static partial void ConfigureInMemory(IDictionary configData)
{
configData.Add("TestService__Version", "1.0.0.0");
}
// Register your services
static partial void AddServices(IServiceCollection services)
{
services
.AddOptions()
.BindConfiguration(nameof(TestService));
services.AddSingleton();
}
// Configure commands
static partial void ConfigureApp(AppServiceConfig appServiceConfig)
{
// Example: Add a root level command
appServiceConfig
.AddCommand("test")
.WithDescription("Example test command.")
.WithExample(["test"]);
// Example: Add nested commands using branches
appServiceConfig
.AddBranch(
"yolo",
c => c.AddCommand("test")
.WithDescription("Example test command.")
.WithExample(["yolo", "test"])
);
// Example: Set application name
appServiceConfig.SetApplicationName("myapp");
}
}
```
This example demonstrates:
- Setting up configuration values in memory for development
- Registering services with dependency injection
- Creating commands at both root and nested levels
- Adding command descriptions and usage examples
The resulting CLI will support commands like:
```bash
myapp test
myapp yolo test
```
## MSBuild Properties
You can customize the build behavior using the following MSBuild properties:
- `UseDefaultProgram`: Set to `false` to opt out of the default Program.cs file generation. This allows you to provide your own custom Program implementation.
```xml
false
```
## Example Projects
- [ARI](https://github.com/devlead/ARI)
- [Blobify](https://github.com/devlead/Blobify)
- [BRI](https://github.com/devlead/bri)
- [DPI](https://github.com/devlead/DPI)
- [UnpackDacPac](https://github.com/devlead/UnpackDacPac)