Skip to main content

Crate tx_di_core

Crate tx_di_core 

Source
Expand description

§tx-di-core

类型驱动的 Rust 依赖注入框架。

§核心概念

  • Component trait — 每个被 DI 管理的类型实现此 trait,用 associated type 声明依赖
  • ComponentMeta — 瘦注册条目,linkme 编译期收集,运行期拓扑排序
  • Store — 类型擦除的组件存储(DashMap<TypeId, CompRef>),运行期解析依赖
  • AOP — Interceptor trait + proc_macro 代理,零运行时开销

§设计原则

  1. 类型驱动:依赖在 type Deps 中声明,编译期可知
  2. 编译期收集:linkme 零开销注册
  3. 运行期解析:拓扑排序 + DashMap 存储
  4. 可扩展: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 String to Value.
registry
组件注册表 — linkme 编译期收集组件元数据
scope
组件作用域
store
Store — 类型擦除的组件存储
topology
拓扑排序 — Kahn 算法

Structs§

ApiR
接口返回结构体
AppErrCode
归一化错误码值类型。
CancellationToken
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.
FormattedDateTime
格式化日期时间包装器

Enums§

AppError
统一错误类型。
RCode
Value
Representation of a TOML value.

Traits§

CodeMsg
错误码转换 trait — 连接业务错误枚举与统一 AppError 的桥梁。

Type Aliases§

ApiRes
接口返回结构体,无数据
AppResult
统一 Result 类型
RIE
RIE = AppResult

Attribute Macros§

intercept
#[intercept] — 标记需要 AOP 拦截的方法

Derive Macros§

CodeMsg
统一错误码 derive 宏。
Component
#[derive(Component)] — 组件 derive 宏