Dependency and injector

Hi,

I am reading the code at:
https://github.com/Xilinx/brevitas

https://github.com/Xilinx/brevitas/blob/master/src/brevitas/inject/__init__.py
In the above file which uses from _dependencies.injector import Injector.

if I navigate to the package from _dependencies.injector import Injector, I could not found any information about this package.

my questions are:
what is the package from _dependencies.injector import Injector?
what is injected to where?
is there any document or tutorial about it?

I found a link in Google:
·https://pypi.org/project/injector·
it looks like the injector in the above link is not the one used in https://github.com/Xilinx/brevitas/blob/master/src/brevitas/inject/__init__.py

Please do not enclose URLs intended to be followed between backticks. This prevents them from becoming links.


I do not understand what you mean by “navigate”. How do you navigate? And how are you looking for the information?


I think it is the package dependencies referred here:

The package on PyPI:

It contains the identifiers used in the code:

Thank you, I got it!

Here, “navigate” means that I go to the package installed in my computer from the editor(pycharm, vscode and ect).

It comes from the dependencies package.

Dependency injection is trivial in Python. It is literally just passing in an argument to the class constructor:


# Without dependency injection.

class ApiClient:

    def __init__(self):

        self.api_key = settings["API_KEY"]  # <-- dependency

        self.timeout = settings["TIMEOUT"]  # <-- dependency



class Service:

    def __init__(self):

        self.api_client = ApiClient()  # <-- dependency





# With dependency injection and inversion of control.



class ApiClient:

    def __init__(self, api_key, timeout):

        self.api_key = api_key  # <-- inject the dependency

        self.timeout = timeout  # <-- inject the dependency





# We can even use defaults to simplify the process.



class Service:

    def __init__(self, client=None):

        if client is None:

            client = ApiClient(settings["API_KEY"], settings["TIMEOUT"])

        self.api_client = client  # <-- inject the dependency



“Dependency injection” is a $1000 name for a $0.10 concept.