python-dependency-injector
python-dependency-injector copied to clipboard
Yet another "Provide object has no attribute ..."
I'm making some initial tests and I'd like to wire my service to my controller. Could anyone please tell me what am I missing?
This is my controller:
This is my container:
This is my project structure:
I'm taking the fastapi example from the docs as a reference. I can't get past this:
File "(...)app\server\controllers\StudentController.py", line 17, in add_student_data
new_student = service.create(body)
AttributeError: 'Provide' object has no attribute 'create'
The whole project can be checked here: https://github.com/elarrat/fastapi-test
I'm kinda stuck in this for days now, so If anyone could take some time to help me I'd very much appreciate it.
in controller, @inject
decorator should be the closest to the injected function. i guess.
Thanks for answering! I did that already, but still a no go. I'm suspecting of the package path in the wiring configurations. It's hard to tell since it doesn't throw any error
same here!
I was getting this error when running my tests and turns out I had a problem in my app fixture:
Incorrect:
@pytest.fixture
def app():
"""App fixture."""
flask_app = create_app()
flask_app.container.unwire()
return flask_app
Correct:
@pytest.fixture
def app():
"""App fixture."""
flask_app = create_app()
yield flask_app
flask_app.container.unwire()