kodemore / kink

Dependency injection container made for Python
MIT License
397 stars 25 forks source link

[QUESTION] How kink works with async? #32

Closed katunilya closed 11 months ago

katunilya commented 1 year ago

Hi!

First of all, thanks for such simple and useful DI!

In readme it is said that kink support "async with asyncio" however I don't see any examples of such functionality. Is it possible to create some fastapi-like async dependency?

Concrete case (sqlalchemy's AsyncSesssion):

async def get_session() -> AsyncSession:
    async_session = sessionmaker(
        engine, class_=AsyncSession, expire_on_commit=False
    )
    async with async_session() as session:
        yield session

I tried I few workaround, but all of them just does not work, as kink understands (as it seems to me) only lambda-based factory functions.

dkraczkowski commented 1 year ago

@katunilya Hello, thank you. Well I think it was a bit of an overstatement. What I meant is kink can inject dependencies into your async functions.

Your usecase is a very interesting thou, and sounds like a good feature request.

katunilya commented 1 year ago

@dkraczkowski thanks for quick response!

Truly I thinks it might be a great feature.