Skip to main content

tx_di_core/
lib.rs

1//! # tx-di-core
2//!
3//! 编译期依赖注入框架的核心运行时支撑层。
4//!
5//! ## 核心概念
6//!
7//! ### Scope(作用域)
8//! - **Singleton**:全局共享,工厂调用一次,缓存 `Arc<T>`
9//! - **Prototype**:每次注入调用工厂,构造新实例
10//!
11//! ### 设计原则
12//! - **scope 标记在被注入的组件上**,消费者字段写裸类型
13//! - 字段类型 `T` 或 `Arc<T>` 均可,框架通过 `TypeId` 找到对应的工厂
14//! - 统一通过 `ctx.inject::<T>()` 注入,自动根据组件自身 scope 决定行为
15
16mod di;
17
18pub use linkme;
19pub use toml;
20pub use toml::Value;
21pub use toml::map;
22
23pub use tx_di_macros::{tx_comp, tx_cst};
24pub use di::{BuildContext,scopes::Scope,
25             comp::{ComponentMeta,topo_sort,COMPONENT_REGISTRY,config::AppAllConfig},
26             comp::comp_ref::{CompRef,ComponentDescriptor,CompInit,BoxFuture}};
27