mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
impl di in handlers with support custom provider
This commit is contained in:
@@ -1,19 +1,28 @@
|
||||
from argenta.app.models import App
|
||||
from argenta.app import App
|
||||
from argenta.response import Response
|
||||
|
||||
from argenta.orchestrator.argparser import ArgParser
|
||||
from argenta.orchestrator.argparser.entity import ArgSpace
|
||||
from argenta.di.integration import setup_dishka
|
||||
from argenta.di.providers import SystemProvider
|
||||
|
||||
from dishka import Provider, make_container
|
||||
|
||||
|
||||
DEFAULT_ARGPARSER: ArgParser = ArgParser(processed_args=[])
|
||||
|
||||
|
||||
class Orchestrator:
|
||||
def __init__(self, arg_parser: ArgParser = DEFAULT_ARGPARSER):
|
||||
def __init__(self, arg_parser: ArgParser = DEFAULT_ARGPARSER,
|
||||
custom_providers: list[Provider] = [],
|
||||
auto_inject_handlers: bool = True):
|
||||
"""
|
||||
Public. An orchestrator and configurator that defines the behavior of an integrated system, one level higher than the App
|
||||
:param arg_parser: Cmd argument parser and configurator at startup
|
||||
:return: None
|
||||
"""
|
||||
self._arg_parser: ArgParser = arg_parser
|
||||
self._custom_providers: list[Provider] = custom_providers
|
||||
self._auto_inject_handlers: bool = auto_inject_handlers
|
||||
|
||||
def start_polling(self, app: App) -> None:
|
||||
"""
|
||||
@@ -21,5 +30,8 @@ class Orchestrator:
|
||||
:param app: a running application
|
||||
:return: None
|
||||
"""
|
||||
parsed_argspace: ArgSpace = self._arg_parser.parse_args()
|
||||
app.run_polling(argspace=parsed_argspace)
|
||||
container = make_container(SystemProvider(self._arg_parser), *self._custom_providers)
|
||||
Response.patch_by_container(container)
|
||||
setup_dishka(app, auto_inject=self._auto_inject_handlers)
|
||||
|
||||
app.run_polling()
|
||||
|
||||
Reference in New Issue
Block a user