Smart.Console.Template 4.0.1

dotnet new install Smart.Console.Template::4.0.1                
This package contains a .NET Template Package you can call from the shell/command line.

Smart.Console.Template

.NET 8/9 NuGet NLog

基于 .NET 通用主机(IHost)的控制台应用快速开发框架,集成依赖注入、配置管理和后台服务支持。

功能特性

1. 现代化控制台架构

  • 基于 Microsoft.Extensions.Hosting 构建
  • 支持后台服务(IHostedService
  • 内置优雅停机(Ctrl+C 中断处理)

2. 开箱即用的组件

  • 配置系统
csharp
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.AddUserSecrets<Program>()
  • 依赖注入
csharp
services.ScanCustomizedServices(); // 自动扫描注册服务

3. 关键设计

csharp
// 中文编码支持(GBK/GB2312)
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

// 后台服务异常处理
services.Configure<HostOptions>(options =>
{
  options.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
});

快速开始

安装

bash
dotnet new install Smart.Console.Template

创建项目

bash
dotnet new smart.console -n MyDemo

添加服务

csharp
// 实现 IHostedService
public class DemoService : BackgroundService
{
  protected override Task ExecuteAsync(CancellationToken stoppingToken)
  {
    // 你的业务逻辑
  }
}

// 通过特性自动注册
[Service(ServiceLifetime.Singleton, InjectScheme.OnlySelf)]
public class DataService
{
  // 你的业务逻辑
}

开发建议

服务注册约定

用户需要了解Smart.Inject框架的用法,访问Smart.Inject

Developed by zenglei

This package has no dependencies.

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
4.0.1 74 2/16/2025
4.0.0 75 2/15/2025
3.2.0 74 2/14/2025
3.1.2 82 2/9/2025
3.1.1 92 12/29/2024
3.1.0 100 12/7/2024
3.0.1 96 12/7/2024
3.0.0 92 12/7/2024
2.0.1 88 11/27/2024
2.0.0 90 11/26/2024
1.0.0.8 109 11/11/2024
1.0.0.7 96 10/30/2024
1.0.0.6 95 10/29/2024
1.0.0.5 94 10/29/2024
1.0.0.4 98 10/29/2024
1.0.0.3 90 10/29/2024
1.0.0.2 90 10/29/2024
1.0.0.1 103 10/27/2024
1.0.0 101 10/22/2024