|
5 | 5 | from ellar.common import ( |
6 | 6 | GlobalGuard, |
7 | 7 | GuardCanActivate, |
8 | | - IApplicationReady, |
9 | 8 | IApplicationShutdown, |
10 | 9 | IApplicationStartup, |
11 | 10 | IExceptionMiddlewareService, |
|
20 | 19 | IWebSocketContextFactory, |
21 | 20 | Module, |
22 | 21 | ) |
23 | | -from ellar.core import ModuleSetup |
| 22 | +from ellar.common.interfaces import ITemplateRenderingService |
| 23 | +from ellar.common.logging import logger |
| 24 | +from ellar.core import ModuleSetup, TemplateRenderingService |
24 | 25 | from ellar.core.conf import Config |
25 | 26 | from ellar.core.exceptions.service import ExceptionMiddlewareService |
26 | | -from ellar.core.execution_context import ExecutionContextFactory, HostContextFactory |
27 | 27 | from ellar.core.execution_context.factory import ( |
| 28 | + ExecutionContextFactory, |
| 29 | + HostContextFactory, |
28 | 30 | HTTPConnectionContextFactory, |
29 | 31 | WebSocketContextFactory, |
30 | 32 | ) |
|
33 | 35 | from ellar.core.services import Reflector, reflector |
34 | 36 | from ellar.di import EllarInjector, ProviderConfig, injectable, request_scope |
35 | 37 | from ellar.di.injector.tree_manager import ModuleTreeManager |
| 38 | +from ellar.events import app_context_started, app_context_teardown |
36 | 39 |
|
37 | 40 | if t.TYPE_CHECKING: # pragma: no cover |
38 | 41 | from ellar.app import App |
@@ -64,6 +67,11 @@ def get_core_module(app_module: t.Union[t.Type, t.Any], config: Config) -> t.Typ |
64 | 67 | use_class=GlobalCanActivatePlaceHolder, |
65 | 68 | export=True, |
66 | 69 | ), |
| 70 | + ProviderConfig( |
| 71 | + ITemplateRenderingService, |
| 72 | + use_class=TemplateRenderingService, |
| 73 | + export=True, |
| 74 | + ), |
67 | 75 | ProviderConfig( |
68 | 76 | ModuleTreeManager, |
69 | 77 | use_value=lambda: config.MODULE_TREE_MANAGER_CLASS( |
@@ -118,18 +126,23 @@ def get_core_module(app_module: t.Union[t.Type, t.Any], config: Config) -> t.Typ |
118 | 126 | ), |
119 | 127 | ], |
120 | 128 | ) |
121 | | - class EllarCoreModule(IApplicationReady, IApplicationStartup, IApplicationShutdown): |
| 129 | + class EllarCoreModule(IApplicationStartup, IApplicationShutdown): |
122 | 130 | def __init__(self, _config: Config, injector: EllarInjector) -> None: |
123 | 131 | self.config = _config |
124 | 132 | self.injector = injector |
125 | 133 |
|
126 | | - def on_ready(self, app: "App") -> None: |
127 | | - pass |
128 | | - |
129 | 134 | async def on_startup(self, app: "App") -> None: |
130 | | - pass |
| 135 | + try: |
| 136 | + await app_context_started.run(app=app) |
| 137 | + except Exception as ex: # pragma: no cover |
| 138 | + logger.exception(ex) |
| 139 | + raise ex |
131 | 140 |
|
132 | 141 | async def on_shutdown(self) -> None: |
133 | | - pass |
| 142 | + try: |
| 143 | + await app_context_teardown.run() |
| 144 | + except Exception as ex: # pragma: no cover |
| 145 | + logger.exception(ex) |
| 146 | + raise ex |
134 | 147 |
|
135 | 148 | return EllarCoreModule |
0 commit comments