# Simple Little Dependency Injection Container
[](http://travis-ci.org/aventurella/pydi)
## Usage:
```python
from pydi import Container
class DogService(object):
def __init__(self, dep):
self.dep = dep
def action(self):
self.dep.action()
class FooService(object):
def __init__(self, dep1, dep2):
self.dep1 = dep1
self.dep2 = dep2
def action1(self):
self.dep1.action()
def action2(self):
self.dep2.action()
class Bar(object):
def action(self):
print('bar')
class Baz(object):
def __init__(self, option):
self.option = option
def action(self):
print('baz!!!', self.option)
class Lucy(object):
def action(self):
print("I'm a dog!")
container = Container()
# shared must be called last. It will reuse an instance
container.register(FooService).depends(Bar).depends(Baz, option="Hello World!").shared()
# without shared, a new instance will be created each time
container.register(DogService).depends(Lucy)
# could also container['FoOSeRViCE']()
obj = container.FooService()
obj.action1()
obj.action2()
print('+-------------+')
# could also container['fooservice']()
obj2 = container.FooService()
obj2.action1()
print('+-------------+')
obj3 = container.FooService()
obj3.action1()
```
[](http://travis-ci.org/aventurella/pydi)
## Usage:
```python
from pydi import Container
class DogService(object):
def __init__(self, dep):
self.dep = dep
def action(self):
self.dep.action()
class FooService(object):
def __init__(self, dep1, dep2):
self.dep1 = dep1
self.dep2 = dep2
def action1(self):
self.dep1.action()
def action2(self):
self.dep2.action()
class Bar(object):
def action(self):
print('bar')
class Baz(object):
def __init__(self, option):
self.option = option
def action(self):
print('baz!!!', self.option)
class Lucy(object):
def action(self):
print("I'm a dog!")
container = Container()
# shared must be called last. It will reuse an instance
container.register(FooService).depends(Bar).depends(Baz, option="Hello World!").shared()
# without shared, a new instance will be created each time
container.register(DogService).depends(Lucy)
# could also container['FoOSeRViCE']()
obj = container.FooService()
obj.action1()
obj.action2()
print('+-------------+')
# could also container['fooservice']()
obj2 = container.FooService()
obj2.action1()
print('+-------------+')
obj3 = container.FooService()
obj3.action1()
```
Metadata
Release files for pydi 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydi-0.3.2.tar.gz | 3.4 kB | Details |
Release files / pydi-0.3.2.tar.gz
| Download URL | pydi-0.3.2.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4b8f23ed79520c175c7ad967441e8257d27617711694b9be4ae2b8d37023698
|
|
BLAKE2b-256 checksum How to use checksums |
e798b577b01ddb85155af763bd0693638421485fc8386cad543f88b416420c14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |