Pythonic dependency injection container
Project description
# pySyringe
[![Build Status](https://travis-ci.org/MichalPodeszwa/pySyringe.svg)](https://travis-ci.org/MichalPodeszwa/pySyringe)
[![Coverage Status](https://coveralls.io/repos/MichalPodeszwa/pySyringe/badge.svg?branch=master&service=github)](https://coveralls.io/github/MichalPodeszwa/pySyringe?branch=master)
This is `pySyringe`. Inversion of Control container, which helps you get proper [`Dependency Injection`](https://en.wikipedia.org/wiki/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
```python
>>> 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`
[![Build Status](https://travis-ci.org/MichalPodeszwa/pySyringe.svg)](https://travis-ci.org/MichalPodeszwa/pySyringe)
[![Coverage Status](https://coveralls.io/repos/MichalPodeszwa/pySyringe/badge.svg?branch=master&service=github)](https://coveralls.io/github/MichalPodeszwa/pySyringe?branch=master)
This is `pySyringe`. Inversion of Control container, which helps you get proper [`Dependency Injection`](https://en.wikipedia.org/wiki/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
```python
>>> 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`
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
pySyringe-1.2.0.tar.gz
(2.1 kB
view details)
File details
Details for the file pySyringe-1.2.0.tar.gz
.
File metadata
- Download URL: pySyringe-1.2.0.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30ebfbab5df576f0dc29c6791ca52c1d1094668f9544e31e48e25de2745d5ebd |
|
MD5 | 7c4033adcad02838a612d720082f3085 |
|
BLAKE2b-256 | 0e346310778d496f375e783ba00f8adfa4751caf7b1ec0b259a70f6144547372 |