Finistere / antidote

Dependency injection for Python
MIT License
90 stars 9 forks source link

Context manager support #25

Open Finistere opened 3 years ago

Finistere commented 3 years ago

Currently @inject does not support any context manager. It would be great to have something like:

from contextlib import contextmanager
from antidote import inject, resource

@resource
@contextamanger
def database_connection():
    # setup
    yield 'the database'
    # cleanup

@inject(dependencies=dict(db=database_connection))  # or Database @ database_connection like factories ?
def f(db):
    pass