forked from danielmoumeny212/pynest_playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pynest_factory.py
32 lines (26 loc) · 840 Bytes
/
pynest_factory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from abc import ABC, abstractmethod
from fastapi import FastAPI
from pynest_application import PyNestApp
from typing import TypeVar, Union
from pynest_container import PyNestContainer
T = TypeVar('T')
class PyNestFactory:
@staticmethod
def _initialize(
module: T,
container: PyNestContainer,
):
container.add_module(module)
@staticmethod
def create(main_module: T, **kwargs) -> PyNestApp:
container = PyNestContainer()
http_server = PyNestFactory._create_server(**kwargs)
PyNestFactory._initialize(main_module,container)
app = PyNestApp(
container,
http_server
)
return app
@staticmethod
def _create_server(**kwargs) -> FastAPI:
return FastAPI(**kwargs)