Skip to main content

Crate tx_di_core

Crate tx_di_core 

Source
Expand description

§tx-di-core

编译期依赖注入框架的核心运行时支撑层。

§核心概念

§Scope(作用域)

  • Singleton:全局共享,工厂调用一次,缓存 Arc<T>
  • Prototype:每次注入调用工厂,构造新实例

§设计原则

  • scope 标记在被注入的组件上,消费者字段写裸类型
  • 字段类型 T 或 Arc<T> 均可,框架通过 TypeId 找到对应的工厂
  • 统一通过 ctx.inject::<T>() 注入,自动根据组件自身 scope 决定行为

Re-exports§

pub use di::comp::COMPONENT_REGISTRY;
pub use linkme;
pub use toml;

Modules§

map
A map of String to Value.

Structs§

AppAllConfig
全局配置文件
BuildContext
ComponentMeta
组件元数据,存储组件的运行时信息和依赖关系。

Enums§

CompRef
存储单元:
Scope
组件的作用域
Value
Representation of a TOML value.

Statics§

COMPONENT_REGISTRY

Traits§

CompInit
组件初始化 trait,用于在依赖注入完成后执行自定义初始化逻辑。
ComponentDescriptor
组件描述符 trait,用于在编译期定义组件的元数据和构建逻辑。

Functions§

topo_sort
对组件元数据进行拓扑排序,确定组件的构建顺序。 Kahn算法

Type Aliases§

BoxFuture

Attribute Macros§

tx_comp
组件宏,标注一个结构体为组件
tx_cst
自定义值宏