proofit404 / dependencies

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

Asynchronous generator support for @operation decorator. #450

Closed proofit404 closed 3 years ago

proofit404 commented 3 years ago

@operation objects are designed to be called inside object which has it as a dependency.

It's totally fine to use them as asynchronous iterables inside asynchronous objects.

This feature does not require Container to be awaited before dependency injection happens.

class App:
    def __init__(self, do):
        self.do = do

    async def run(self):
        async for action in self.do():
            print(action)

class Container(Injector):
    app = App

    @operation
    async def do():
        yield 1
        yield 2
        yield 3

await Container.app.run()  # prints 1, 2, and 3
proofit404 commented 3 years ago

Superseded by #457