Skip to content

How to fail application if dependency cannot be wired? #538

Open
@gtors

Description

@gtors

For example, developer make typo in Provide[...]:

container.py

class ApplicationContainer(containers.DeclarativeContainer):
    some_service = providers.Singleton(object)

app.py

# FastAPI

@app.get("/")
@inject
async def some_handler(service = Depends(Provide["sOme_service"])):  # suppose there is a typo in the name of the container attribute
    # `service` will be <dependency_injector.wiring.Provide object at 0x7f59daf8c580>
    pass

I've tried this approach, but it doesn't work for the Singleton:

Provide["some_service", required()]  # AttributeError: 'dependency_injector.providers.Singleton' object has no attribute 'required'

So, how to crash app in case if dependency cannot be resolved?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions