Skip to content

v2.1.0

Latest

Choose a tag to compare

@RobertoPrevato RobertoPrevato released this 08 Mar 19:30
58e86c6
  • Improve resolve() typing, by @sobolevn.

  • Use Self type for Container, by @sobolevn.

  • Improve typing of inject, by @sobolevn.

  • Do not ignore _globalns that is set via inject(), by @sobolevn. Address an inconsistency: inject(globalsns=...) silently had no effect during class/init resolution even though the parameter was stored — users passing a custom globalsns would get no error but also no result. The factory path already honoured it, so this brings the two resolution paths into.
    parity.

  • Drop support for Python <= 3.10.

  • Add Python 3.14 to the build matrix and to classifiers.

  • Remove Codecov from GitHub Workflow and from README.

  • Upgrade type annotations to Python >= 3.10.

  • Remove code checks for Python <= 3.10.

  • Support mixing __init__ parameters and class-level annotated properties for
    dependency injection. Previously, when a class defined a custom __init__,
    rodi would only inspect constructor parameters and ignore class-level type
    annotations. Now both are resolved: constructor parameters are injected as
    arguments, and any remaining class-level annotated properties are injected via
    setattr after instantiation. This enables patterns like:

    class MyService:
        extra_dep: ExtraDependency  # injected via setattr
    
        def __init__(self, main_dep: MainDependency) -> None:
            self.main_dep = main_dep

    Resolves issue #43, reported by @lucas-labs.

  • Add support for the decorator pattern
    via Container.decorate(base_type, decorator_type). The decorator class must have an
    __init__ parameter whose type annotation matches the registered type; that parameter
    receives the inner service instance, while all other parameters are resolved from the
    container as usual. Decorators can be chained by calling decorate() multiple times —
    each call wraps the previous registration:

    container.add_singleton(IGreeter, SimpleGreeter)
    container.decorate(IGreeter, LoggingGreeter)     # wraps SimpleGreeter
    container.decorate(IGreeter, CachingGreeter)     # wraps LoggingGreeter
    # resolves as: CachingGreeter(LoggingGreeter(SimpleGreeter()))

    Resolves issue #15, requested by @Eldar1205.