Skip to content

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

@HoopsMcann

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
    ...

Metadata

Metadata

Assignees

Labels

No labels
No labels
No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions