Coder Social home page Coder Social logo

py3njection's Introduction

Py3njection

Build Status Tests status Documentation Status Join the chat at https://gitter.im/Aigrefin/py3njection

How to use

from py3njection import inject
from some_package import ClassToInject

class Demo:
    @inject
    def __init__(self, object_to_use: ClassToInject):
        self.dependency = object_to_use

demo = Demo()

How does it work ?

The decorator @inject looks for any annotated method/function parameters (return annotation excluded).

It creates a new object from the specified class if no object is already provided.

What if I want a singleton ?

@singleton
class ClassToInject:
    pass

That's it ! When @inject sees a class with this decorator, it always uses the same instance.

How to install

It's available on PyPI !

pip install py3injection

Or get it at : https://pypi.python.org/pypi/py3njection

Want to know more ?

A more complete documentation is available here : http://py3njection.readthedocs.org/en/latest/

Contact and Contribution

Feel free to contribute in any way :

Some Notes

  • Unit tests come easy to set up (unless you have too many dependencies, but that would be a code smell, right ?). Just specify mock instances at your object creation. Examples will come later.
  • This also means the injected object could also have some of its members injected too at their initialization !

py3njection's People

Contributors

aigrefin avatar gitter-badger avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

gitter-badger

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.