2021-02-27 17:45:49 +03:00
|
|
|
from flask import Flask, jsonify, request, current_app, session, g
|
|
|
|
from flask import _request_ctx_stack, _app_ctx_stack
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
from dependency_injector.wiring import inject, Provide
|
|
|
|
|
|
|
|
# This is here for testing wiring bypasses these objects without crashing
|
|
|
|
request, current_app, session, g # noqa
|
|
|
|
_request_ctx_stack, _app_ctx_stack # noqa
|
|
|
|
|
|
|
|
|
|
|
|
class Service:
|
|
|
|
def process(self) -> str:
|
2021-10-18 23:19:03 +03:00
|
|
|
return "OK"
|
2021-02-27 17:45:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
|
|
|
service = providers.Factory(Service)
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
2021-10-01 03:09:42 +03:00
|
|
|
@app.route("/")
|
2021-02-27 17:45:49 +03:00
|
|
|
@inject
|
|
|
|
def index(service: Service = Provide[Container.service]):
|
|
|
|
result = service.process()
|
2021-10-01 03:09:42 +03:00
|
|
|
return jsonify({"result": result})
|
2021-02-27 17:45:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
container = Container()
|
2021-10-01 03:09:42 +03:00
|
|
|
container.wire(modules=[__name__])
|