proofit404 / dependencies

Constructor injection designed with OOP in mind.
https://proofit404.github.io/dependencies/
BSD 2-Clause "Simplified" License
360 stars 18 forks source link

Injector should be awaitable. #133

Open proofit404 opened 5 years ago

proofit404 commented 5 years ago

Value decorator can be applied to the coroutine functions.

In this case, we should be able to await them before injection.

Any attribute access on Injector should start dependency injection process.

So we need to make Injector awaitable itself.

class Container(Injector):
    app = App

    @value
    async def pool(loop):
        return await Pool(loop)

await (await Container(loop=loop)).app.process()

In the case of asyncio user should put initiated loop instance inside injection scope manually.

See #114.

thedrow commented 5 years ago

In case of trio user should put the nursery inside the injection scope manually.

proofit404 commented 5 years ago

Thanks for clarification!

Indeed, it should.