Skip to content

MichalPodeszwa/pySyringe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pySyringe

Build Status Coverage Status

This is pySyringe. Inversion of Control container, which helps you get proper Dependency Injection, while still being Pythonic.

Currently pySyringe works only on Python 3.3+. Maybe later, support for older versions will be added.

Installation

pip install pysyringe

Usage

>>> import pysyringe
>>>
>>> class Foo:
...
...     def __init__(self):
...         self.bar = 42
...
>>> @pysyringe.inject(foo=Foo)
... def important_function(foo):
...     return foo.bar
...
>>> important_function()
42

>>> class Mock:
...     def __init__(self):
...         self.bar = 1
...
>>> important_function(Mock())
>>>
>>> @pysyringe.inject_value(foo=42)
... def important_function2(foo):
...     return foo
>>> important_function2()
42

As you can see testing is a lot simpler now. You don't need as much (hopefully none) mocking as you used to.

If pySyringe injects the same class twice, it doesn't create instances twice, it simply returns previous one.

Testing

  1. Clone this repository
  2. Run python setup.py develop
  3. Install pytest from pip
  4. Run py.test

About

Pythonic dependency injection container

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages