# Vampirewal.Core
**Repository Path**: vampirewal/Vampirewal.Core
## Basic Information
- **Project Name**: Vampirewal.Core
- **Description**: 快速开发wpf程序的一个框架,还在完善中
- **Primary Language**: C#
- **License**: MIT
- **Default Branch**: master
- **Homepage**: https://vampirewal.gitee.io/
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 1
- **Created**: 2023-01-24
- **Last Updated**: 2026-04-24
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[](https://www.nuget.org/packages/Vampirewal.Core/)
[](https://www.nuget.org/packages/Vampirewal.Core/)
[](LICENSE)
[](https://jq.qq.com/?_wv=1027\&k=857529437)
Vampirewal.Core
基于 .NET 的企业级应用快速开发框架
***
## 📖 简介
**Vampirewal.Core** 是一个功能完善的 .NET 企业级应用快速开发框架,提供从数据访问、业务逻辑到界面展示的全栈解决方案。框架内置完善的 MVVM 架构支持、IoC 依赖注入、事件总线、工作流引擎、审批流引擎等核心功能,帮助开发者快速构建高质量的桌面应用程序。
## 🖥 支持环境
- .NET 6.0
- .NET 7.0
- .NET 8.0
## ✨ 核心特性
### 🏗 架构设计
| 特性 | 说明 |
| ----------- | ---------------------------------------------------- |
| **MVVM 架构** | 完整的 MVVM 模式支持,基于 CommunityToolkit.Mvvm |
| **依赖注入** | 基于 Microsoft.Extensions.DependencyInjection 的 IoC 容器 |
| **模块化设计** | 支持模块独立开发和按需加载 |
| **源码生成器** | 内置 Source Generator,自动生成 MVVM 样板代码 |
### 🎨 WPF UI 框架
| 特性 | 说明 |
| ------------- | --------------- |
| **自定义控件库** | 提供丰富的 WPF 自定义控件 |
| **主题系统** | 统一的应用主题和样式管理 |
| **MDI 多文档界面** | 支持多文档界面布局 |
| **对话框服务** | 统一的弹窗、通知、提示框服务 |
| **数据验证** | 完整的数据验证服务 |
### 📦 功能模块
| 模块 | 说明 |
| ------------- | ------------------------- |
| **数据访问** | 基于 SqlSugar 的 ORM,支持多种数据库 |
| **事件总线** | 轻量级事件总线,支持发布/订阅模式 |
| **工作流引擎** | 可视化工作流设计器和执行引擎 |
| **审批流引擎** | 灵活的审批流程设计 |
| **定时任务** | 基于 IJob 的定时任务调度 |
| **规则引擎** | 可配置的规则执行引擎 |
| **HTTP 客户端** | 封装的 HTTP 请求服务 |
| **Excel 操作** | 数据导入导出服务 |
| **Socket 通信** | Socket 服务器和客户端支持 |
***
## 📚 项目结构
```
Vampirewal.Core/
├── Vampirewal.Core/ # 核心库
│ ├── Components/ # 核心组件服务
│ ├── SimpleMVVM/ # MVVM 基础架构
│ ├── Models/ # 数据模型
│ ├── Tools/ # 工具类
│ ├── Attributes/ # 自定义特性
│ ├── Extensions/ # 扩展方法
│ ├── GeneralTree/ # 通用树结构
│ └── ConfigOptions/ # 配置选项
│
├── Vampirewal.Core.WPF.Theme/ # WPF 主题控件库
│ ├── CustomControl/ # 自定义控件
│ ├── FrameworkControl/ # 框架控件
│ ├── Behaviors/ # 交互行为
│ ├── Converter/ # 值转换器
│ └── Application/ # 应用服务
│
├── Vampirewal.Core.EventBus/ # 事件总线
├── Vampirewal.Core.VContainer/ # IoC 容器
├── Vampirewal.Core.Mapper/ # 对象映射
├── Vampirewal.Core.HttpClientService/ # HTTP 客户端
├── Vampirewal.Core.WebApi/ # Web API 服务
├── Vampirewal.Core.MiniApi/ # Mini API 框架
├── Vampirewal.Core.SocketServer/ # Socket 服务
├── Vampirewal.Core.ScheduledTask/ # 定时任务
├── Vampirewal.Core.RuleEngine/ # 规则引擎
├── Vampirewal.Core.FlowEngine/ # 工作流引擎
├── Vampirewal.Core.ApprovalFlowEngine/ # 审批流引擎
├── Vampirewal.Core.OperationExcelService/# Excel 操作服务
├── Vampirewal.Core.ComputerInfo/ # 系统信息
├── Vampirewal.Core.SubMessageService/ # 子消息服务
├── Vampirewal.Core.SourceGeneratorMvvm/ # MVVM 源码生成器
├── Vampirewal.Core.ClassObjectPool/ # 对象池
├── Vampirewal.Core.YuQueHelper/ # 语雀助手
├── Vampirewal.Console.Core/ # 控制台核心
└── Game/Vampirewal.ECS/ # ECS 游戏引擎
```
***
## 🚀 快速开始
### 1. 安装 NuGet 包
```bash
dotnet add package Vampirewal.Core
dotnet add package Vampirewal.Core.WPF.Theme
```
### 2. 创建启动类
继承 `VampirewalBootStartUp` 并实现必要的抽象方法:
```csharp
public class BootStartUp : VampirewalBootStartUp
{
protected override string FirstViewKey => "MainWindow";
protected override void RegisterService(IServiceCollection services)
{
// 注册自定义服务
}
public override void OnAppRun(bool IsRun)
{
// 程序启动时执行
}
public override void OnAppExit(bool IsRun)
{
// 程序关闭时执行
}
}
```
### 3. 注册 View 和 ViewModel
使用 `[VampirewalIoCRegister]` 特性注册视图和视图模型:
```csharp
[VampirewalIoCRegister(Token = "MainWindow", Type = ClassType.Normal)]
public partial class MainWindow : WindowBase
{
public MainWindow()
{
InitializeComponent();
}
}
[VampirewalIoCRegister(Token = "MainVM", Type = ClassType.Normal)]
public partial class MainViewModel : ViewModelBase
{
[ObservableProperty]
private string title = "欢迎使用";
}
```
### 4. 启动应用程序
```csharp
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var boot = new BootStartUp();
boot.BuildBootStartUp(e.Args);
}
}
```
***
## 📖 核心模块详解
### 1. MVVM 架构
框架提供完整的 MVVM 基础类,简化视图模型开发:
#### ViewModelBase
所有 ViewModel 的基类,提供属性通知和命令支持:
```csharp
public partial class MainViewModel : ViewModelBase
{
[ObservableProperty]
private string title = "标题";
[RelayCommand]
private void ExecuteCommand()
{
// 命令执行逻辑
}
public override void InitData()
{
// 初始化数据
}
}
```
#### BillListBaseVM
列表查询 ViewModel 基类,提供分页、搜索、弹窗等功能:
```csharp
public class UserListVM : BillListBaseVM
{
protected override void InitVM()
{
// 初始化
}
protected override IUcViewBase SetView()
{
return WindowsManager.GetInstance().GetView("UserEditView", "UserEditVM");
}
[RelayCommand]
protected override void ExecuteSearch(string searchText)
{
GetPageList(
x => string.IsNullOrEmpty(searchText) || x.Name.Contains(searchText),
x => x.CreateTime,
OrderByType.Desc
);
}
}
```
#### BillVM
单据详情 ViewModel 基类,提供增删改查和明细数据管理:
```csharp
public class UserEditVM : BillVM
{
public UserEditVM(SqlSugarRepository rep) : base(rep)
{
}
public override void BillVmInitData()
{
// 初始化逻辑
}
}
```
### 2. IoC 容器
框架提供两种 IoC 容器方案:
#### Microsoft.Extensions.DependencyInjection
主容器,通过 `VampirewalCoreContext` 管理:
```csharp
// 获取服务
var service = VampirewalCoreContext.GetInstance().GetService();
// 创建实例
var instance = VampirewalCoreContext.GetInstance().CreateInstance();
// 配置管理
var options = VampirewalCoreContext.GetInstance().GetOptions();
VampirewalCoreContext.GetInstance().SetOptions(options);
```
### 3. 数据模型
#### 模型层级
| 模型 | 说明 |
| ------------------- | ---------------------------------------- |
| **TopModel** | 模型最顶层基类,包含 BillId 等基础字段 |
| **BaseModel** | 继承 TopModel,添加 UpdateTime、UpdateBy 等审计字段 |
| **BillBaseModel** | 单据基类,包含单据号、状态等业务字段 |
| **DetailBaseModel** | 明细数据基类 |
#### 数据访问
基于 SqlSugar ORM,支持多种数据库:
```csharp
// Repository 注入
public class UserService
{
private SqlSugarRepository _rep;
public UserService(SqlSugarRepository rep)
{
_rep = rep;
}
public List GetUsers()
{
return _rep.Queryable.Where(x => x.IsDelete == false).ToList();
}
}
```
支持的数据库类型:
- MySQL
- SQL Server
- SQLite
- Oracle
- PostgreSQL
- 达梦 (DM)
- KingbaseES
- Oscar
### 4. 事件总线
支持发布/订阅模式的事件通信:
```csharp
// 定义事件消息
public class UserCreatedEvent
{
public string UserName { get; set; }
}
// 发布事件
VampirewalCoreContext.GetInstance()
.GetService()
.Publish(new UserCreatedEvent { UserName = "张三" });
// 订阅事件(使用特性)
[SubscribeEvent]
public class UserEventHandler : IEventHandler
{
public Task Handle(UserCreatedEvent @event)
{
Console.WriteLine($"用户 {@event.UserName} 已创建");
return Task.CompletedTask;
}
}
```
### 5. 窗口管理
统一的窗口管理服务:
```csharp
// 打开窗口
WindowsManager.GetInstance().OpenWindow("MainWindow");
// 以对话框方式打开窗口
var result = WindowsManager.GetInstance()
.OpenDialogWindow("UserEditView", "UserEditVM", param);
// 关闭指定窗口
WindowsManager.GetInstance().CloseWindow(viewId);
// 获取当前活动窗口
var activeWindow = WindowsManager.GetInstance().GetActivateWindows();
```
### 6. 自定义控件
WPF 主题库提供丰富的自定义控件:
| 控件 | 说明 |
| --------------------- | --------- |
| **BlockContainer** | 块容器控件 |
| **Calendar** | 日历控件 |
| **DataGrid** | 数据网格(增强版) |
| **EditContainer** | 编辑容器 |
| **FlowDesign** | 流程设计器 |
| **LoadingContainer** | 加载动画容器 |
| **MaskDialogGrid** | 遮罩对话框 |
| **MdiContainer** | MDI 容器 |
| **NumTextBox** | 数字输入框 |
| **VPagination** | 分页控件 |
| **PropertyInfoPanel** | 属性信息面板 |
| **RadarChart** | 雷达图控件 |
| **SearchControl** | 搜索控件 |
| **Transfer** | 穿梭框控件 |
| **TreeListView** | 树形列表视图 |
| **UGrid** | 增强网格控件 |
### 7. 工作流引擎
可视化的工作流设计和执行:
```csharp
// 创建工作流
var builder = VampirewalCoreContext.GetInstance()
.GetService();
// 添加节点
builder.AddNode("Start", FlowNodeType.Start);
builder.AddNode("Approval", FlowNodeType.Task);
builder.AddNode("End", FlowNodeType.End);
// 连接节点
builder.AddLink("Start", "Approval");
builder.AddLink("Approval", "End");
// 执行工作流
var engine = VampirewalCoreContext.GetInstance()
.GetService();
engine.Execute(builder.Build());
```
### 8. 审批流引擎
灵活的审批流程配置:
```csharp
public class LeaveApproval : ApprovalFlowBase
{
[FlowParam("请假天数")]
public int Days { get; set; }
[UserSelector("审批人")]
public string Approver { get; set; }
protected override void BuildFlow()
{
// 根据天数设置不同的审批流程
if (Days <= 3)
{
AddNode("部门主管审批", Approver);
}
else
{
AddNode("部门主管审批", Approver);
AddNode("总经理审批", "总经理");
}
}
}
```
### 9. 定时任务
基于 IJob 接口的定时任务调度:
```csharp
public class DataSyncJob : IJob
{
public async Task ExecuteAsync(JobContext context)
{
// 执行数据同步任务
await SyncData();
}
}
// 配置任务
var option = new JobOption
{
Cron = "0 0 * * *", // 每天凌晨执行
JobType = typeof(DataSyncJob)
};
```
### 10. 工具类
框架提供丰富的工具方法:
| 工具类 | 功能 |
| ------------------- | --------- |
| **Utils** | 通用工具方法 |
| **FileHelper** | 文件操作 |
| **JsonHelper** | JSON 序列化 |
| **DateTimeHelper** | 日期时间处理 |
| **EnumHelper** | 枚举操作 |
| **DESHelper** | DES 加密解密 |
| **ZipHelper** | 压缩解压 |
| **Base64ZipHelper** | Base64 压缩 |
| **GZipHelper** | GZip 压缩 |
| **RandomHelper** | 随机数生成 |
| **PoolManager** | 对象池管理 |
***
## 🎯 最佳实践
### 配置管理
使用 JSON 配置文件:
```json
{
"AppBaseOptions": {
"AppName": "我的应用",
"Version": "1.0.0"
},
"DbBaseOptions": {
"DbType": "MySql",
"ConnectionString": "server=localhost;database=mydb;uid=root;pwd=123456"
}
}
```
### 全局上下文
使用 `VampirewalCoreContext` 存储全局数据:
```csharp
// 存储数据
VampirewalCoreContext.GetInstance().AddContext("UserName", "张三");
VampirewalCoreContext.GetInstance().AddContext("UserId", "001");
// 获取数据
VampirewalCoreContext.GetInstance().GetContext("UserName", out var name);
```
### 消息中心
使用 Messenger 进行 ViewModel 间通信:
```csharp
// 发送消息
Messenger.Default.Send(new UserSelectedMessage { UserId = "001" });
// 注册接收消息
[MessengerAop]
public void ReceiveUserSelected(UserSelectedMessage message)
{
// 处理消息
}
```
### 数据验证
```csharp
public class UserInput : ValidationBaseModel
{
[Required(ErrorMessage = "用户名不能为空")]
[MaxLength(50, ErrorMessage = "用户名长度不能超过50")]
public string UserName { get; set; }
[EmailAddress(ErrorMessage = "邮箱格式不正确")]
public string Email { get; set; }
}
```
***
## 📦 NuGet 包列表
| 包名 | 说明 |
| ----------------------------------------- | ----------- |
| **Vampirewal.Core** | 核心库 |
| **Vampirewal.Core.WPF.Theme** | WPF 主题控件库 |
| **Vampirewal.Core.EventBus** | 事件总线 |
| **Vampirewal.Core.VContainer** | IoC 容器 |
| **Vampirewal.Core.HttpClientService** | HTTP 客户端 |
| **Vampirewal.Core.WebApi** | Web API 服务 |
| **Vampirewal.Core.MiniApi** | Mini API 框架 |
| **Vampirewal.Core.ScheduledTask** | 定时任务 |
| **Vampirewal.Core.RuleEngine** | 规则引擎 |
| **Vampirewal.Core.FlowEngine** | 工作流引擎 |
| **Vampirewal.Core.ApprovalFlowEngine** | 审批流引擎 |
| **Vampirewal.Core.OperationExcelService** | Excel 操作 |
| **Vampirewal.Core.ComputerInfo** | 系统信息 |
| **Vampirewal.Core.SocketServer** | Socket 服务 |
| **Vampirewal.Core.Mapper** | 对象映射 |
| **Vampirewal.Core.SubMessageService** | 子消息服务 |
| **Vampirewal.Core.SourceGeneratorMvvm** | MVVM 源码生成器 |
| **Vampirewal.Core.ClassObjectPool** | 对象池 |
| **Vampirewal.Core.YuQueHelper** | 语雀助手 |
| **Vampirewal.Console.Core** | 控制台核心 |
***
## 🤝 交流与支持
- **QQ 交流群**: [857529437](https://jq.qq.com/?_wv=1027\&k=857529437)
- **项目地址**: [Gitee](http://vampirewal.gitee.io/)
- **问题反馈**: 请在 Gitee 提交 Issue
***
## 📄 开源协议
本项目基于 [MIT License](LICENSE) 开源协议
```
MIT License
Copyright (c) 2023 vampirewal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
***
## ⭐ 贡献指南
1. Fork 本仓库
2. 创建您的特性分支 (`git checkout -b feature/AmazingFeature`)
3. 提交您的更改 (`git commit -m 'Add some AmazingFeature'`)
4. 推送到分支 (`git push origin feature/AmazingFeature`)
5. 提交 Pull Request
***
Made with ❤️ by Vampirewal
© 2023 Vampirewal. All rights reserved.