|
1 | 1 | import dataclasses |
2 | 2 |
|
3 | 3 | import litestar |
| 4 | +import modern_di |
4 | 5 | import modern_di_litestar |
5 | 6 | from advanced_alchemy.exceptions import DuplicateKeyError |
6 | 7 | from lite_bootstrap import LitestarBootstrapper |
7 | 8 | from litestar.config.app import AppConfig |
8 | 9 | from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor |
9 | 10 | from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor |
10 | 11 |
|
11 | | -from app import exceptions, ioc |
| 12 | +from app import exceptions, ioc, repositories |
12 | 13 | from app.api.decks import ROUTER |
13 | 14 | from app.settings import settings |
14 | 15 |
|
15 | 16 |
|
16 | 17 | def build_app() -> litestar.Litestar: |
| 18 | + di_container = modern_di.AsyncContainer(groups=[ioc.Dependencies]) |
17 | 19 | bootstrap_config = dataclasses.replace( |
18 | 20 | settings.api_bootstrapper_config, |
19 | 21 | application_config=AppConfig( |
20 | 22 | exception_handlers={ |
21 | 23 | DuplicateKeyError: exceptions.duplicate_key_error_handler, |
22 | 24 | }, |
23 | 25 | route_handlers=[ROUTER], |
24 | | - plugins=[modern_di_litestar.ModernDIPlugin()], |
| 26 | + plugins=[modern_di_litestar.ModernDIPlugin(di_container)], |
25 | 27 | dependencies={ |
26 | | - "decks_service": modern_di_litestar.FromDI(ioc.Dependencies.decks_service), |
27 | | - "cards_service": modern_di_litestar.FromDI(ioc.Dependencies.cards_service), |
| 28 | + "decks_service": modern_di_litestar.FromDI(repositories.DecksService), |
| 29 | + "cards_service": modern_di_litestar.FromDI(repositories.CardsService), |
28 | 30 | }, |
29 | 31 | request_max_body_size=settings.request_max_body_size, |
30 | 32 | ), |
|
0 commit comments