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.0.2.tar.gz
(2.5 kB
view hashes)
Built Distribution
Close
Hashes for ntt_injector-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7dde2d41ec4593d370e7daa41b1390d89542f0d6d268950c8ce9c76bc17da81 |
|
MD5 | 4e152465b4d468feafc6305af0eae15a |
|
BLAKE2b-256 | af6ad29f69181f4b6a181e93649e540fec15f8e2fbb1ecbf6c0720407ff69d28 |