@@ -73,6 +73,7 @@ class BookModule(ModuleBase):
7373
7474
7575## ` Additional Module Configurations `
76+
7677### ` Module Events `
7778Every registered Module receives two event calls during its instantiation and when application is ready.
7879
@@ -87,11 +88,43 @@ class ModuleEventSample(ModuleBase):
8788 """ Called before creating Module object"""
8889
8990 def application_ready (self , app : App) -> None :
90- """ Called when application is ready"""
91+ """ Called when application is ready - this is similar to @on_startup event """
9192
9293```
9394` before_init ` receives current app ` Config ` as a parameter and ` application_ready ` function receives ` App ` instance as parameter.
9495
96+ #### ` Starlette Application Events `
97+ We can register multiple event handlers for dealing with code that needs to run before
98+ the application starts ` up ` , or when the application is shutting ` down ` .
99+ This is the way we support ` Starlette ` start up events in ` Ellar `
100+
101+ ``` python
102+
103+ from ellar.common import Module, on_shutdown, on_startup
104+ from ellar.core import ModuleBase
105+
106+ @Module ()
107+ class ModuleRequestEventsSample (ModuleBase ):
108+ @on_startup
109+ def on_startup_func (cls ):
110+ pass
111+
112+ @on_startup ()
113+ async def on_startup_func_2 (cls ):
114+ pass
115+
116+ @on_shutdown
117+ def on_shutdown_func (cls ):
118+ pass
119+
120+ @on_shutdown ()
121+ async def on_shutdown_func_2 (cls ):
122+ pass
123+ ```
124+ These will be registered to the application router during ` ModuleRequestEventsSample ` computation at runtime.
125+ Also, the events can be ` async ` as in the case of ` on_shutdown_func_2 ` and ` on_startup_func_2 `
126+
127+
95128### ` Module Exceptions `
96129In Ellar, custom exceptions can be registered through modules.
97130During module meta-data computation, Ellar reads additional properties such as these from registered modules
@@ -132,35 +165,6 @@ class ModuleTemplateFilterSample(ModuleBase):
132165 def double_filter_dec (cls , n ):
133166 return n * 2
134167```
135- ### ` Module Request Events `
136- During application request handling, application router emits two events ` start_up ` and ` shutdown ` event.
137- We can subscribe to those events in our modules.
138- ``` python
139-
140- from ellar.common import Module, on_shutdown, on_startup
141- from ellar.core import ModuleBase
142-
143- @Module ()
144- class ModuleRequestEventsSample (ModuleBase ):
145- @on_startup
146- def on_startup_func (cls ):
147- pass
148-
149- @on_startup ()
150- async def on_startup_func_2 (cls ):
151- pass
152-
153- @on_shutdown
154- def on_shutdown_func (cls ):
155- pass
156-
157- @on_shutdown ()
158- async def on_shutdown_func_2 (cls ):
159- pass
160- ```
161- These will be registered to the application router during ` ModuleRequestEventsSample ` computation at runtime.
162- Also, the events can be ` async ` as in the case of ` on_shutdown_func_2 ` and ` on_startup_func_2 `
163-
164168
165169## ` Dependency Injection `
166170A module class can inject providers as well (e.g., for configuration purposes):
0 commit comments