# slack
a DI Container
## register and provide
```python
from slack import Container
c = Container()
class Component:
def __init__(self):
pass
c.register('component', Component)
c1 = c.provide('component')
c2 = c.provide('component') # c1 is c2
```
## dependency inject
```python
class Component:
def __init__(self, dep1, dep2):
pass
c.register('dep1', Dep1)
c.register('dep2', Dep2)
c.register('component', Component)
c.provide('component')
```
## partial inject
```python
class Component:
def __init__(self, dep1, dep2):
pass
NewComponent = c.inject(Component, 'dep1')
c = NewComponent(dep2)
```
## using decorator
```python
c.register('comp1')
def comp1(dep1, dep2):
return SomeClass()
```
## apply
```python
def fn(a, b):
pass
@c.register('b')
def provide_b():
pass
c.apply(fn, a=val)
```
## groups and reset
```python
@c.register('comp', group='once')
class Component:
pass
comp1 = c.provide('comp')
comp2 = c.provide('comp') # comp1 is comp2
c.reset('once')
comp3 = c.provide('comp') # comp3 is not comp2
```
Raw data
{
"_id": null,
"home_page": "https://github.com/zweifisch/slack",
"name": "slack",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "DI Container",
"author": "Feng Zhou",
"author_email": "zf.pascal@gmail.com",
"download_url": "UNKNOWN",
"platform": "UNKNOWN",
"description": "# slack\n\na DI Container\n\n## register and provide\n\n```python\nfrom slack import Container\n\nc = Container()\n\nclass Component:\n def __init__(self):\n pass\n\nc.register('component', Component)\n\nc1 = c.provide('component')\nc2 = c.provide('component') # c1 is c2\n```\n\n## dependency inject\n\n```python\nclass Component:\n def __init__(self, dep1, dep2):\n pass\n\nc.register('dep1', Dep1)\nc.register('dep2', Dep2)\nc.register('component', Component)\nc.provide('component')\n```\n\n## partial inject\n\n```python\nclass Component:\n def __init__(self, dep1, dep2):\n pass\n\nNewComponent = c.inject(Component, 'dep1')\n\nc = NewComponent(dep2)\n```\n\n## using decorator\n\n```python\nc.register('comp1')\ndef comp1(dep1, dep2):\n return SomeClass()\n```\n\n## apply\n\n```python\ndef fn(a, b):\n pass\n\n@c.register('b')\ndef provide_b():\n pass\n\nc.apply(fn, a=val)\n```\n\n## groups and reset\n\n```python\n@c.register('comp', group='once')\nclass Component:\n pass\n\ncomp1 = c.provide('comp')\ncomp2 = c.provide('comp') # comp1 is comp2\n\nc.reset('once')\n\ncomp3 = c.provide('comp') # comp3 is not comp2\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "a DI container",
"version": "0.0.3",
"split_keywords": [
"di",
"container"
],
"urls": [],
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "zweifisch",
"github_project": "slack",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "slack"
}