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
60
61
62
63
64
65
66
use Arc;
use crate::;
define_error!;
/// Helper function to inject a dependency from the DI container within route handlers
///
/// This function retrieves a service of type `T` from the dependency injection container.
/// It uses the task-local `App` instance set up by the `AppLayer`.
///
/// # Example
///
/// ```rust
/// use lxy::utils::inject;
/// use lxy::Result;
///
/// struct MyService;
///
/// async fn my_handler() -> Result<()> {
/// // Inject a service from the DI container
/// let my_service = inject::<MyService>()?;
///
/// // do with my_service
/// // ...
/// Ok(())
/// }
/// ```
///
/// # Errors
///
/// Returns an error if:
/// - The factory of type `T` is not registered in the container
/// - The dependencies of type `T` is not registered in the container
/// - This function is called outside of a route handler context (where App is not available)
/// Helper macro for injecting dependencies with less boilerplate
///
/// # Example
///
/// ```rust
/// use lxy::inject;
/// use lxy::Result;
///
/// struct MyService;
///
/// async fn my_handler() -> Result<()> {
/// let my_service = inject!(MyService)?;
///
/// // use my_service
/// // ...
/// Ok(())
/// }
/// ```