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
-`ModuleB` references `ModuleA` using `ForwardRefModule`, meaning `ModuleB` knows about `ModuleA` but doesn't instantiate it.
299
+
- 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.
300
+
301
+
This pattern is particularly useful when modules need to reference each other, creating a situation where they might otherwise be instantiated out of order or cause circular dependencies.
302
+
303
+
### Forward Reference by Name
304
+
305
+
`ForwardRefModule` also supports referencing a module by its name, allowing for even more flexibility. This is beneficial when module classes are defined in separate files or when the module class may not be available at the time of reference.
306
+
307
+
```python
308
+
from ellar.common import Module
309
+
from ellar.core.modules import ForwardRefModule, ModuleBase, ModuleRefBase
-`ModuleB` references `ModuleA` by its name, `"moduleA"`.
330
+
- During the build process of `ApplicationModule`, the name reference is resolved, ensuring that `ModuleA` is instantiated and injected into `ModuleB` correctly.
331
+
332
+
This method allows you to define module dependencies without worrying about the order of their definition,
333
+
providing greater modularity and flexibility in your application's architecture.
334
+
335
+
By using `ForwardRefModule`, you can build complex,
336
+
interdependent module structures without running into
337
+
issues related to instantiation order or circular dependencies,
338
+
making your codebase more maintainable and easier to manage.
0 commit comments