Skip to main content

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)

Uploaded Source

Built Distribution

ntt_injector-1.1.0-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page