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/overview/modules.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -289,10 +289,23 @@ class ApplicationModule(ModuleBase):
289
289
The `JWTModule` provides `JWTService` which is injected into `CustomModule`. By declaring `ForwardRefModule(JWTModule)` in `CustomModule`, the `JWTService` will be properly resolved during instantiation of `CustomModule`, regardless of the order in which the modules are configured in the application.
290
290
291
291
This pattern is particularly useful when:
292
+
292
293
- You want to avoid direct module instantiation
293
294
- You need to configure a module differently in different parts of your application
294
295
- You want to maintain loose coupling between modules
295
296
297
+
### When not to use `ForwardRefModule`
298
+
If the @Module class is registered in the application module, ApplicationModule, there is no need to use `ForwardRefModule`. Services/Providers exported from the module will be available in the application module. And all other modules will be able to resolve the dependencies from the application module.
299
+
300
+
```python
301
+
from ellar.common import Module
302
+
from ellar.core.modules import ForwardRefModule, ModuleBase
303
+
304
+
@Module(modules=[ModuleA])
305
+
classApplicationModule(ModuleBase):
306
+
pass
307
+
```
308
+
296
309
### Forward Reference by Class
297
310
298
311
In the following example, we have two modules, `ModuleA` and `ModuleB`. `ModuleB`
@@ -321,6 +334,7 @@ class ApplicationModule(ModuleBase):
321
334
```
322
335
323
336
In this example:
337
+
324
338
-`ModuleB` references `ModuleA` using `ForwardRefModule`, meaning `ModuleB` knows about `ModuleA` but doesn't instantiate it.
325
339
- When `ApplicationModule` is built, both `ModuleA` and `ModuleB` are instantiated. During this build process, `ModuleB` can reference the instance of `ModuleA`, ensuring that all dependencies are resolved properly.
326
340
@@ -352,6 +366,7 @@ class ApplicationModule(ModuleBase):
352
366
```
353
367
354
368
In this second example:
369
+
355
370
-`ModuleB` references `ModuleA` by its name, `"moduleA"`.
356
371
- During the build process of `ApplicationModule`, the name reference is resolved, ensuring that `ModuleA` is instantiated and injected into `ModuleB` correctly.
0 commit comments