Skip to content

Aggregate providers must use the .provider attribute for injection Markers #948

Description

@HoopsMcann

Description

While trying to inject a provider.Aggregate into my FastAPI endpoint I discovered that using the marker pattern: Provider[foo] does not work as expected, contrary to what the documentation indicates docs

Example

class ServiceA
    ...

class ServiceB
   ...

class Container(containers.DeclaritiveContainer):
    serviceA = providers.Factory(ServiceA)
    serviceB = providers.Factory(ServiceB)

    services = providers.Aggregate(serviceA=serviceA, serviceB=serviceB)


container = Container()
container.wire(modules=[__name__])

@router.post("/v1")
@inject
async def my_endpoint(dummy: TestPost, service=Depends(Provide[Container.services])): # <-- TypeError: missing 1st required positional argument: "provider name"
    ...

# However, this works:
@router.post("/v1")
@inject
async def my_endpoint(dummy: TestPost, service=Depends(Provide[Container.services.provider])): # <-- Works as expected
    ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions