The small library for configuring the depedency injector design pattern
Project description
Library for creating Dependency Injection Pattern
Usage
from nttinjector import dependency_inject, Injector
class Model:
count = 0
def __init__(self, strName: str = "") -> None:
self._strName = strName
self.CreateNewModel()
def __repr__(self) -> str:
return f"<Model name=\"{self._strName}\" />"
@classmethod
def CreateNewModel(cls):
cls.count += 1
@classmethod
def GetModelInstances(cls):
return cls.count
@dependency_inject(Model)
class ViewModel:
count = 0
def __init__(self, mModel: Model, strName: str = "") -> None:
self._mModel = mModel
self._strName = strName
self.CreateNewModel()
@classmethod
def CreateNewModel(cls):
cls.count += 1
@classmethod
def GetModelInstances(cls):
return cls.count
def __repr__(self) -> str:
return f"<ViewModel name=\"{self._strName}\" />"
@dependency_inject(ViewModel, Model)
class View:
def __init__(self, viewModel: ViewModel, mModel: Model, strName: str = "") -> None:
self._viewModel = viewModel
self._model = mModel
self._strName = strName
def __repr__(self) -> str:
return f"<View name=\"{self._strName}\" />"
Then use the View as normal
view = View()
print(view._model)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ntt-injector-1.1.0.tar.gz
(2.6 kB
view hashes)
Built Distribution
Close
Hashes for ntt_injector-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fb757968869e6009a1ddce0bad74d8be551d7639cccb59d4f8649f1ede81e38 |
|
MD5 | 4208a691d7b6941617b24329315bd6e3 |
|
BLAKE2b-256 | f485f9d6fb98429d4aece9641be11bc7fbad92a986a06e3960e48d7a49992fec |