Skip to content

Allow dependency providers with arguments. #178

Description

@xelandernt

Common difficulty which currently requires some kind of "work-around"

@app.get("/")
async def endpont(r: Request, value = fastapi.Depends(Container.provider)):
    ...

Where the provider is actually a dependent of the Request

def get_dependency_based_on_request(r: Request) : 
    ...

class Container(BaseContainer):
    provider = providers.SomeProvider(get_dependency_based_on_request)

Feature request

  • Allow providers to accept arguments during resolution, i.e. when calling provider.resolve() or providers.resolve_sync()
  • Allow to pass function arguments to injected dependencies (similar to fastapi.Depends() )

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestv3Relevant to version 3.*

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions