Just another python DI library.
Project description
# pyhooker
Lightweight and easy-to-use python dependency injection library
Pyhooker is ready to use for Python >=2.7 and >=3.2
[![Build Status](https://travis-ci.org/sighalt/pyhooker.svg?branch=master)](https://travis-ci.org/sighalt/pyhooker)
## Installation
```
pip install git+https://github.com/sighalt/pyhooker.git
```
## Usage
```python
import pyhooker
# wheel.py
class IWheel(object):
pass
class MichelinWheel(IWheel):
pass
# engine.py
class IEngine(object):
pass
class OttoEngine(IEngine):
pass
# car.py
class ICar(object):
pass
class Car(ICar):
@pyhooker.inject_params(engine=IEngine, wheel_type=IWheel)
def __init__(self, engine, wheel_type):
self.engine = engine
self.wheel_type = wheel_type
# driver.py
class Driver(object):
@pyhooker.inject_params(car=ICar)
def __init__(self, car):
self.car = car
# __init__.py
pyhooker.register(ICar, Car)
pyhooker.register(IEngine, OttoEngine)
pyhooker.register(IWheel, MichelinWheel)
driver = Driver()
print("The driver is %s\n... with its car %s\n... and engine %s\n... and wheel type %s" % (driver,
driver.car,
driver.car.engine,
driver.car.wheel_type))
```
Lightweight and easy-to-use python dependency injection library
Pyhooker is ready to use for Python >=2.7 and >=3.2
[![Build Status](https://travis-ci.org/sighalt/pyhooker.svg?branch=master)](https://travis-ci.org/sighalt/pyhooker)
## Installation
```
pip install git+https://github.com/sighalt/pyhooker.git
```
## Usage
```python
import pyhooker
# wheel.py
class IWheel(object):
pass
class MichelinWheel(IWheel):
pass
# engine.py
class IEngine(object):
pass
class OttoEngine(IEngine):
pass
# car.py
class ICar(object):
pass
class Car(ICar):
@pyhooker.inject_params(engine=IEngine, wheel_type=IWheel)
def __init__(self, engine, wheel_type):
self.engine = engine
self.wheel_type = wheel_type
# driver.py
class Driver(object):
@pyhooker.inject_params(car=ICar)
def __init__(self, car):
self.car = car
# __init__.py
pyhooker.register(ICar, Car)
pyhooker.register(IEngine, OttoEngine)
pyhooker.register(IWheel, MichelinWheel)
driver = Driver()
print("The driver is %s\n... with its car %s\n... and engine %s\n... and wheel type %s" % (driver,
driver.car,
driver.car.engine,
driver.car.wheel_type))
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyhooker-1.0.1.tar.gz
(25.7 kB
view details)
File details
Details for the file pyhooker-1.0.1.tar.gz
.
File metadata
- Download URL: pyhooker-1.0.1.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2e734197d9bcfe0610c1c17b8144aabf7486da64ff1ecc4244ad699a71afa85 |
|
MD5 | a085810bfa8ee21dd9d5ed8bf6fc2e0d |
|
BLAKE2b-256 | 8ba569a58844c2e9225ee73b50f8d983039de4f31dca5cf9024bae74bbf83cbb |