You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/basics/application-context.md
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,22 @@
1
-
# **Application Context**
1
+
# **Injector Context**
2
2
3
3
In the complex web of dependencies within Ellar,
4
4
accessing the application instance without triggering circular import errors can be a daunting task.
5
5
6
-
To address this challenge, Ellar introduces the concept of an application context,
6
+
To address this challenge, Ellar introduces the concept of an injector context,
7
7
a powerful mechanism that facilitates smooth access to the application instance throughout various parts of the codebase.
8
8
9
-
## **Understanding the Application Context**
9
+
## **Understanding the Injector Context**
10
10
11
-
The application context serves as a bridge between different components of the application, making the application object
11
+
The Injector context serves as a bridge between different components of the application, making the application object
12
12
readily available through the application Dependency Injection (DI) container. This ensures that you can access the
13
13
application instance without encountering import issues, whether it's during request handling, execution of CLI commands,
14
14
or manual invocation of the context.
15
15
16
16
Two key elements of the application context are:
17
17
18
18
-**current_injector**: This proxy variable refers to the current application **injector**, providing access to any service or the application instance itself.
19
-
-**config**: A lazy loader for application configuration, which is based on the `ELLAR_CONFIG_MODULE` reference or accessed through `application.config` when the application context is active.
19
+
-**current_config**: A lazy loader for application configuration, which is based on the `ELLAR_CONFIG_MODULE` reference or accessed through `application.config` when the application context is active.
20
20
21
21
## **Integration with Click Commands**
22
22
@@ -27,7 +27,7 @@ For instance, consider the following example:
27
27
28
28
```python
29
29
import ellar_cli.click as click
30
-
from ellar.appimport current_injector
30
+
from ellar.coreimport current_injector
31
31
from ellar.di import injectable
32
32
33
33
@injectable
@@ -37,7 +37,7 @@ class MyService:
37
37
38
38
@click.command()
39
39
@click.argument('name')
40
-
@click.with_app_context
40
+
@click.with_injector_context
41
41
defmy_command(name: str):
42
42
my_service = current_injector.get(MyService)
43
43
my_service.do_something()
@@ -63,8 +63,9 @@ For example, consider the following event handling setup:
63
63
64
64
```python
65
65
from ellar.events import app_context_teardown, app_context_started
66
-
from ellar.app import App, AppFactory, current_injector
67
-
from ellar.threading import run_as_async
66
+
from ellar.app import App, AppFactory
67
+
from ellar.core import current_injector, injector_context
0 commit comments