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
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.