WitchC.ExceptionHandler 1.0.0.1

dotnet add package WitchC.ExceptionHandler --version 1.0.0.1
                    
NuGet\Install-Package WitchC.ExceptionHandler -Version 1.0.0.1
                    
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="WitchC.ExceptionHandler" Version="1.0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WitchC.ExceptionHandler" Version="1.0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="WitchC.ExceptionHandler" />
                    
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 WitchC.ExceptionHandler --version 1.0.0.1
                    
#r "nuget: WitchC.ExceptionHandler, 1.0.0.1"
                    
#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 WitchC.ExceptionHandler@1.0.0.1
                    
#: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=WitchC.ExceptionHandler&version=1.0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=WitchC.ExceptionHandler&version=1.0.0.1
                    
Install as a Cake Tool

README - WitchC Framework

╔═══════════════════════════════════════════════════╗
║                W i t c h C  🧙♀️                   ║
║            .NET 企业级应用开发框架              ║
║      (Wicked Intelligent .NET Core Framework)    ║
╚═══════════════════════════════════════════════════╝

📋 项目介绍

WitchC 是一个基于 .NET 8 的企业级应用开发框架,旨在提供简单、灵活、高效的开发体验。本框架从零开始构建,借鉴了优秀框架的设计理念,同时保持代码的清晰和可维护性。

✨ 特性亮点

🎯 核心特性

  • 零配置启动 - 一行代码启动应用
  • 智能依赖注入 - 多层级服务解析策略
  • 程序集自动扫描 - 动态加载和发现
  • 优雅的异常处理 - 全局异常拦截
  • 灵活的配置管理 - 多源配置支持

📦 已实现模块

  • 🔧 核心模块 (WitchC.Core)

    • App 静态门面类
    • 智能服务提供者
    • 全局配置管理
    • 程序集扫描器
  • 🌐 Web模块 (WitchC.Web)

    • 中间件管道
    • 统一响应格式
    • 自动 API 文档
    • 请求验证
  • 🗃️ 数据模块 (WitchC.Data)

    • 仓储模式支持
    • 工作单元
    • 数据过滤器

🚀 快速开始

安装

# 从 NuGet 安装
Install-Package WitchC

基础使用

// Program.cs
using WitchC;

// 一行代码启动应用
await App.RunAsync(args, (context, services) =>
{
    // 注册你的服务
    services.AddControllers();
    services.AddSwaggerGen();
});

高级配置

// 自定义启动配置
var builder = App.CreateBuilder(args);

builder.ConfigureFramework(options =>
{
    options.ApplicationName = "MyAwesomeApp";
    options.EnableAutoScan = true;
    options.LogLevel = LogLevel.Information;
});

builder.Services.AddCustomModule<MyModule>();

var app = builder.Build();
await app.RunAsync();

📁 项目结构

WitchC/
├── src/
│   ├── WitchC.Core/          # 核心框架
│   │   ├── App.cs           # 全局应用类
│   │   ├── DependencyInjection/  # DI容器
│   │   ├── Configuration/   # 配置管理
│   │   └── Extensions/      # 扩展方法
│   │
│   ├── WitchC.Web/          # Web扩展
│   │   ├── Middlewares/     # 中间件
│   │   ├── Filters/         # 过滤器
│   │   └── Routing/         # 路由
│   │
│   └── WitchC.Data/         # 数据访问
│
├── samples/                 # 示例项目
├── tests/                  # 单元测试
└── docs/                   # 文档

🔧 技术栈

  • .NET 8 - 底层运行时
  • ASP.NET Core - Web 框架
  • Microsoft.Extensions.* - 配置/日志/DI
  • Swashbuckle.AspNetCore - API 文档
  • xUnit/NSubstitute - 测试框架

📖 核心概念

1. 应用生命周期

// 启动前
App.OnStarting += (sender, e) => { /* 启动前逻辑 */ };

// 启动中
App.OnStarted += (sender, e) => { /* 启动后逻辑 */ };

// 停止时
App.OnStopping += (sender, e) => { /* 停止前逻辑 */ };

2. 服务解析策略

// 自动解析服务
var service = App.GetService<IMyService>();

// 智能解析(4层策略)
// 1. 单例服务 -> 根容器
// 2. HttpContext -> 请求容器
// 3. 创建新作用域
// 4. 创建新提供者

3. 配置管理

// 获取配置
var value = App.GetConfig<string>("ConnectionStrings:Default");

// 强类型配置
var options = App.GetOptions<DatabaseOptions>();

// 热更新配置
var monitor = App.GetOptionsMonitor<AppSettings>();
monitor.OnChange(options => { /* 配置变化处理 */ });

🧪 示例项目

Web API 示例

[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
    private readonly IUserService _userService;
    
    public UsersController(IUserService userService)
    {
        _userService = userService;
    }
    
    [HttpGet]
    public async Task<IActionResult> GetUsers()
    {
        var users = await _userService.GetAllAsync();
        return Ok(users);
    }
}

控制台应用示例

class Program
{
    static async Task Main(string[] args)
    {
        await App.StartConsoleAsync(async serviceProvider =>
        {
            var worker = serviceProvider.GetRequiredService<IBackgroundWorker>();
            await worker.ExecuteAsync();
        });
    }
}

🔄 开发指南

添加新模块

  1. src/ 下创建新项目
  2. 实现 IModule 接口
  3. 在启动时注册模块

扩展框架功能

// 创建扩展方法
public static class WitchCExtensions
{
    public static IServiceCollection AddMyFeature(this IServiceCollection services)
    {
        services.AddSingleton<IMyFeature, MyFeature>();
        return services;
    }
}

📈 性能优化

  • ✅ 延迟加载程序集
  • ✅ 服务实例缓存
  • ✅ 配置项缓存
  • ✅ 异步初始化
  • ✅ 资源池管理

🐛 故障排除

常见问题

Q: 启动时找不到 IServiceCollection 类型 A: 确保项目中引用了 Microsoft.AspNetCore.App 框架引用

Q: 程序集扫描失败 A: 检查 appsettings.json 中的框架配置,确保程序集路径正确

Q: 服务解析返回 null A: 确认服务已正确注册,检查服务生命周期

调试模式

// appsettings.Development.json
{
  "Framework": {
    "EnableDebug": true,
    "LogLevel": "Debug",
    "PrintAssemblyInfo": true
  }
}

🤝 贡献指南

  1. Fork 项目
  2. 创建功能分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 开启 Pull Request

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情

📞 支持与联系

  • 📧 邮箱:support@witchc.dev
  • 🐙 GitHub Issues: 提交问题报告
  • 💬 讨论区:功能讨论和想法

🎯 路线图

v1.0.0 (当前)

  • 核心框架搭建
  • 基本依赖注入
  • 配置管理
  • Web 扩展

v1.1.0 (规划中)

  • 分布式缓存
  • 消息队列
  • 工作流引擎
  • 监控仪表板

v2.0.0 (远景)

  • 微服务支持
  • 云原生适配
  • AI 集成
  • 低代码平台

╔═══════════════════════════════════════════════════╗
║   感谢使用 WitchC 框架!让我们一起创造魔法!   ║
║   Let's make some magic with .NET! ✨             ║
╚═══════════════════════════════════════════════════╝

最后更新: 2024年1月

Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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 is compatible.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • 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
1.0.0.1 102 3/22/2026