1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Application hosting and dependency injection.
//!
//! ```
//! use hosting::{Service, ServiceCollection, abstraction};
//! use std::sync::Arc;
//!
//! #[derive(Service)]
//! struct Database;
//!
//! #[derive(Service)]
//! struct Repository {
//! db: Arc<Database>,
//! }
//!
//! #[abstraction]
//! trait Notifier: Send + Sync {
//! fn notify(&self, message: &str);
//! }
//!
//! #[derive(Service)]
//! struct Email;
//!
//! impl Notifier for Email {
//! fn notify(&self, _message: &str) {}
//! }
//!
//! #[derive(Service)]
//! struct Signup {
//! repository: Arc<Repository>,
//! notifiers: Vec<Arc<dyn Notifier>>,
//! }
//!
//! let mut services = ServiceCollection::new();
//! services
//! .add_singleton::<Database>()
//! .add_scoped::<Repository>()
//! .add_singleton_as::<dyn Notifier, Email>()
//! .add_transient::<Signup>();
//! let provider = services.build()?;
//!
//! let scope = provider.create_scope();
//! let signup = scope.resolve::<Signup>()?;
//! for notifier in &signup.notifiers {
//! notifier.notify("welcome");
//! }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use ;
pub use ;
pub use ;
pub use __private;