No project description provided
Project description
# dependency injection
A dependency injection framework for python.
Just like `Microsoft.Extensions.DependencyInjection`.
## Usage
``` py
class A:
pass
class B:
def __init__(self, a: A):
assert isinstance(a, A)
import dependencyinjection as di
service = di.Services()
service.scoped(A)
service.singleton(B)
provider = service.build()
assert isinstance(provider.get(A), A)
assert isinstance(provider.get(B), B)
with provider.scope() as scoped_provider:
assert provider.get(A) is provider.get(A)
assert scoped_provider.get(B) is scoped_provider.get(B)
assert provider.get(B) is scoped_provider.get(B)
assert not (provider.get(A) is scoped_provider.get(A))
```
A dependency injection framework for python.
Just like `Microsoft.Extensions.DependencyInjection`.
## Usage
``` py
class A:
pass
class B:
def __init__(self, a: A):
assert isinstance(a, A)
import dependencyinjection as di
service = di.Services()
service.scoped(A)
service.singleton(B)
provider = service.build()
assert isinstance(provider.get(A), A)
assert isinstance(provider.get(B), B)
with provider.scope() as scoped_provider:
assert provider.get(A) is provider.get(A)
assert scoped_provider.get(B) is scoped_provider.get(B)
assert provider.get(B) is scoped_provider.get(B)
assert not (provider.get(A) is scoped_provider.get(A))
```
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
Built Distribution
Close
Hashes for dependencyinjection-0.1.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0946f8e2e90de71538ec87913a3c1894df739d2cba701a2a488cd1135ebe901 |
|
MD5 | 4381fa5bfcf0e7695588af6850eeb90c |
|
BLAKE2b-256 | 45e32590f64a2d652428312bdf082170b7de80b2b39e610f5ea1f73e66d067d6 |
Close
Hashes for dependencyinjection-0.1.3.0-py3.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 320d892179afa7cd7f2d8df4aac2320a10d83f3c102b35370a9a78566335de65 |
|
MD5 | 94e4f1c643adab4dd9a987cfba17fa1f |
|
BLAKE2b-256 | da5719ed53f3c2fa1ea7e5174fe45faa083c768b212218b92f46269387f93886 |