springtime_di/lib.rs
1//! A dependency injection crate inspired by the [Spring Framework](https://spring.io/) in Java.
2//!
3//! The philosophy of **Springtime** is to provide the means of easy dependency injection without
4//! unnecessary manual configuration, e.g. without the need to explicitly create dependencies and
5//! storing them in containers. As much work as possible is placed on compile-time metadata creation
6//! and automatic [component] discovery, thus allowing users to focus on the _usage_ of components,
7//! rather than their _creation_ and _management_. With an accent placed on attributes,
8//! dependency configuration becomes declarative (_what I want to accomplish_) leaving the gritty
9//! details the framework itself (_how to accomplish what was requested_).
10//!
11//! ### Simple usage example
12//!
13//! ```
14//! use springtime_di::component::Component;
15//! use springtime_di::instance_provider::ComponentInstancePtr;
16//! use springtime_di::{Component, component_alias, injectable};
17//!
18//! // this is a trait we would like to use in our component
19//! #[injectable]
20//! trait TestTrait {}
21//!
22//! // this is a dependency which implements the above trait and also is an injectable component
23//! #[derive(Component)]
24//! struct TestDependency;
25//!
26//! // we're telling the framework it should provide TestDependency when asked for dyn TestTrait
27//! #[component_alias]
28//! impl TestTrait for TestDependency {}
29//!
30//! // this is another component, but with a dependency
31//! #[derive(Component)]
32//! struct TestComponent {
33//! // the framework will know how to inject dyn TestTrait, when asked for TestComponent
34//! // more details are available in other parts of the documentation
35//! dependency: ComponentInstancePtr<dyn TestTrait + Send + Sync>,
36//! }
37//! ```
38//!
39//! *Note:* `Send + Sync` are only required when the `threadsafe` feature is enabled.
40//!
41//! ### Features
42//!
43//! * `derive` - automatically import helper proc macros
44//! * `threadsafe` - use threadsafe pointers and `Send + Sync` trait bounds
45//! * `async` - turn all creation functions async
46
47pub mod component;
48pub mod component_registry;
49pub mod factory;
50#[cfg(feature = "async")]
51pub mod future;
52pub mod instance_provider;
53pub mod scope;
54
55#[cfg(feature = "derive")]
56pub use springtime_di_derive::*;