Expand description
§tx-di-core
类型驱动的 Rust 依赖注入框架。
§核心概念
- Component trait — 每个被 DI 管理的类型实现此 trait,用 associated type 声明依赖
- ComponentMeta — 瘦注册条目,linkme 编译期收集,运行期拓扑排序
- Store — 类型擦除的组件存储(DashMap<TypeId, CompRef>),运行期解析依赖
- AOP — Interceptor trait + proc_macro 代理,零运行时开销
§设计原则
- 类型驱动:依赖在
type Deps中声明,编译期可知 - 编译期收集:linkme 零开销注册
- 运行期解析:拓扑排序 + DashMap 存储
- 可扩展:ComponentMeta 只存核心字段,生命周期钩子在 trait 默认方法中
Re-exports§
pub use crate::error::DiErr;pub use component::BoxFuture;pub use component::Component;pub use component::DepsTuple;pub use config::AppAllConfig;pub use lifecycle::App;pub use lifecycle::BuildContext;pub use lifecycle::InnerContext;pub use lifecycle::get_sys_config;pub use lifecycle::set_sys_config;pub use lifecycle::CONFIG_PATH;pub use registry::ComponentMeta;pub use registry::COMPONENT_REGISTRY;pub use scope::Scope;pub use store::Store;pub use store::CompRef;pub use store::TraitImplEntry;pub use store::TraitImplMap;pub use store::inject_from_store;pub use store::inject_trait_from_store;pub use store::inject_all_traits_from_store;pub use topology::topo_sort;pub use aop::CallContext;pub use aop::CallResult;pub use aop::Interceptor;pub use aop::InterceptorChain;pub use dashmap;pub use linkme;pub use toml;
Modules§
- aop
- AOP 拦截器 — 横切关注点分离
- component
- Component trait — 类型驱动的依赖注入核心
- config
- 全局配置管理
- error
- tx-di-core 错误处理
- lifecycle
- 生命周期管理 — BuildContext 和 App
- map
- A map of
Stringto Value. - registry
- 组件注册表 — linkme 编译期收集组件元数据
- scope
- 组件作用域
- store
- Store — 类型擦除的组件存储
- topology
- 拓扑排序 — Kahn 算法
Structs§
- ApiR
- 接口返回结构体
- AppErr
Code - 归一化错误码值类型。
- Cancellation
Token - A token which can be used to signal a cancellation request to one or more tasks.
- DashMap
- DashMap is an implementation of a concurrent associative array/hashmap in Rust.
- Formatted
Date Time - 格式化日期时间包装器
Enums§
Traits§
- CodeMsg
- 错误码转换 trait — 连接业务错误枚举与统一
AppError的桥梁。
Type Aliases§
Attribute Macros§
- intercept
#[intercept]— 标记需要 AOP 拦截的方法