Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingDependencyError if class declared in a module with __main__ part #178

Open
belegnar opened this issue Sep 9, 2023 · 0 comments
Open

Comments

@belegnar
Copy link

belegnar commented Sep 9, 2023

Hello

# app.py
import aiohttp.web
import punq

from project import routes


class A:
    pass


if __name__ == "__main__":
    container = punq.Container()
    container.register(A, instance=A())

    app = aiohttp.web.Application()
    app["container"] = container
    routes.setup_routes(app)
    aiohttp.web.run_app(app)
# routes.py
import aiohttp.web

from project import view


def setup_routes(app: aiohttp.web.Application):
    app.router.add_route("GET", "/route", view.handler)
# view.py
import aiohttp.web
import punq

from project import app


async def handler(r: aiohttp.web.Request):
    c: punq.Container = r.app["container"]
    c.resolve(app.A)
    return aiohttp.web.Response()

Request to /route results in MissingDependencyError because it exists as __main__.A as I understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant