Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add DI for ASGI routes #1798

Open
Sehat1137 opened this issue Sep 16, 2024 · 1 comment
Open

Feature: Add DI for ASGI routes #1798

Sehat1137 opened this issue Sep 16, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Sehat1137
Copy link
Contributor

Sehat1137 commented Sep 16, 2024

Is your feature request related to a problem? Please describe.
My app may have different dependencies that I want check using k8s probes (database, s3, etc)

Describe the solution you'd like
I need possibility using DI for access to my dependency

Feature code example

from faststream import FastStream, Depends
from faststream.rabbit import RabbitBroker

broker = RabbitBroker("amqp://guest:guest@localhost:5672/")
app = FastStream(broker)

def simple_dependency() -> int:
    return 1

async def readiness(scope, receive, send, d: int = Depends(simple_dependency)):
    assert d == 1
    return AsgiResponse(b"", status_code=200)

app = FastStream(broker).as_asgi(
    asgi_routes=[
        ("/readiness", readiness),
    ],
    asyncapi_path="/docs",
)
@Sehat1137 Sehat1137 added the enhancement New feature or request label Sep 16, 2024
@nightblure
Copy link

nightblure commented Nov 6, 2024

@Sehat1137 hi!
this seems to work with the injection decorator:

from fast_depends import inject

@inject
async def readiness(scope, receive, send, d: int = Depends(simple_dependency)):
    assert d == 1
    return AsgiResponse(b"", status_code=200)

maybe there will be a question about where it is better to import, but anyway..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants