ivankorobkov / python-inject

Python dependency injection
Apache License 2.0
672 stars 77 forks source link

Implement autoparams leveraging types annotations #21

Closed Enforcer closed 5 years ago

Enforcer commented 5 years ago

autoparams docs:

"""
Return a decorator which automatically injects arguments into a function that uses type annotations.
    This is supported only in Python >= 3.5.

    For example::

        @inject.autoparams()
        def refresh_cache(cache: RedisCache, db: DbInterface):
            pass

    There is an option to specify which arguments we want to inject without attempts of injecting everything:

    For example::

        @inject.autoparams('cache', 'db')
        def sign_up(name, email, cache, db):
            pass
"""
Enforcer commented 5 years ago

@ivankorobkov if this looks fine to you and you decide to merge, please release new version afterwards. For now I have no more ideas

ivankorobkov commented 5 years ago

Wow, that's a great one. Thanks for splitting the tests.

ivankorobkov commented 5 years ago

I will try to release a new version today if I have enough time.

ivankorobkov commented 5 years ago

I have added you autoparams example to the readme, added you to the contributors section and released version 3.4.0. As usual you can get it from PyPi https://pypi.org/project/Inject/