Skip to content

feat: Only autowire transitive edges between manually wired dependencies #88

@adriangb

Description

@adriangb

di does auto wiring for dependencies which is super convenient to avoid boilerplate. But let's say you have something like:

class DBConnection:
    def __init__(self, host: str) -> None:
        ...

We (wrongly) assume that this can be constructed like DBConnection(host=str()). This is because we inspect the type annotation and autowire str itself!

We need some way of cutting off how deep we auto-wire. I think a sensible rule would be "all of the leaf dependencies (dependencies with no further dependencies) must be manually wired with:

  • Marker(function_that_accepts_no_arguments)
  • A default value
  • A bind

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions