Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

deps

Python >=3.6 dependency injection based on attrs. Very simple, yet powerful.

Inspired by inject-attrs.

Usage

depsworks only with typing annotations defined as presented below!

  1. First, replace your @attr.s(...) decorators:
    @attr.s(auto_attribs=True, <otherargs/kwargs...>)classThing:
    cfg: Configsome_dep: SomeClass
    With:
    importdeps
    @deps.s(<otherargs/kwargs...>)
    classThing:
    cfg: IConfigsome_dep: ISomeClass

    Notice that auto_attribs=True is no more needed, it will be forced by this package.

  2. Next you have to prepare - somewhere in your codebase - an abstract interfaces classes for your attributes:
    importdepsclassIConfig(deps.Interface)
    # ...classISomeClass(deps.Interface)
    # ...
  3. Now prepare interfaces implementations:
    frominterfacesimportIConfig, ISomeClassclassConfig(IConfig)
    # ...classSomeClass(ISomeClass)
    # ...
  4. Finally, configure dependency injection bindings provided by Inject package, using bind_to_constructor directive.

License

MIT

Creator

Daniel Kuruc

About

Python Package: Dependency injection based on attrs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages