feat: Spring 风格 DI 模块深度优化与框架完善 - #2
Open
xiusin wants to merge 4 commits into
Open
Conversation
Co-authored-by: traeagent <traeagent@users.noreply.github.com>
- pool.v: 移除泛型闭包包装器修复 C 编译错误,改用 call_factory_voidptr 辅助方法绕过 V 0.5.1 的 !&T 返回类型 bug - app.v: 移除 v.reflection 导入(运行时 panic 的根因),改用 comptime 特性($if field.typ is Context、$if T !is $interface、field.indirections) - di/builder.v: 同步移除 v.reflection,inject_on 接口检查改用 comptime - middleware/compress.v: 修复 header.get() 结果传播 - examples/example.v: 新增事件监听演示,修复 text() 返回值传播 - README.md: 完整重写,新增 DI、事件系统、会话管理、配置等章节 - checklist.md / tasks.md: 自审全部勾选完成
Co-authored-by: traeagent <traeagent@users.noreply.github.com>
Co-authored-by: traeagent <traeagent@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
参考 Spring 框架对 DI 模块及整个框架进行深度优化,实现合理的功能、正确的逻辑、易用的 API。
主要变更
DI 模块(Spring 风格重写)
BeanScope枚举(singleton / prototype / request)三作用域BeanDefinition结构(name/type/scope/factory/init/deinit/lazy/primary)Bean结构(definition + instance + initialized 标志)Container提供register_singleton/register_factory/register_lazy/bind_instanceAPIContainer.get[T]带类型校验,不匹配返回明确错误create_request_container()实现 request 作用域子容器隔离Builder/Service/inject_on/get[T])作为兼容别名框架集成
Application持有独立Container(不再使用全局默认)app.register_singleton/register_factory/register_lazy/bind_instanceContext.di[T]先查 request 容器再查 root 容器handle中受enable_request_scope开关控制创建 request 子容器mount[T]支持接口类型字段注入,去除平台分支,统一C.memcpy指针赋值事件模块(新增
event/)Event接口 +EventListener类型 +EventBus(线程安全 register/emit/off)ServerStartEvent/ServerShutdownEvent/RequestStartEvent/RequestEndEventapp.run()emit ServerStart,graceful_shutdownemit ServerShutdown,每个请求 emit RequestStart/RequestEnd会话优化
SessionStore接口(get/set/delete/exists/gc)MemorySessionStore作为默认内存实现Session持有&MemorySessionStore,所有读写走 storeget过期逻辑(返回空 map 且 exists=false)app.set_session_store可替换存储验证器优化
Required支持 int/i64/u64/f64/boolMin/Max补全 f64 字段分支Number对数值类型直接返回 okvalidate中 rule 解析的 mut 覆盖隐患配置扩展
profile、enable_request_scope、max_request_scope_size字段关键 Bug 修复
v.reflection依赖(运行时array.first: array is empty崩溃的根因),改用 V comptime 特性pool.v泛型闭包导致的 C 编译错误,改用call_factory_voidptr辅助方法绕过 V 0.5.1 的!&T返回类型 bugmiddleware/compress.v中header.get()结果传播文档与示例
examples/example.v演示事件监听与新 DI 用法验证结果
v test .→ 4 passed, 4 totalv build-module .→ 成功v -W build-module examples/example.v→ 无错误无警告测试覆盖
di_test.v:singleton / prototype / lazy / 接口绑定 / 类型校验 / request 隔离 / 父容器委托 / has-remove-clear / 兼容 inject_on / factory singletonevent_test.v:基本注册分发 / 多监听器 / off / off_all / 内置事件 / emit 内置事件 / 无监听器 / 监听器错误传播validate_test.v:required int/f64/bool / number int / min-max f64 / 未知验证器pool_test.v:对象池 acquire/release 回收复用