{"id":24738647,"url":"https://github.com/zweifisch/slack","last_synced_at":"2025-03-22T18:42:52.323Z","repository":{"id":15369378,"uuid":"18100497","full_name":"zweifisch/slack","owner":"zweifisch","description":"a DI container","archived":false,"fork":false,"pushed_at":"2014-05-27T08:05:41.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T00:10:49.484Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zweifisch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-25T13:07:22.000Z","updated_at":"2014-05-27T08:05:42.000Z","dependencies_parsed_at":"2022-08-25T08:11:27.613Z","dependency_job_id":null,"html_url":"https://github.com/zweifisch/slack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fslack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fslack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fslack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fslack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zweifisch","download_url":"https://codeload.github.com/zweifisch/slack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245006650,"owners_count":20546136,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-27T22:55:13.591Z","updated_at":"2025-03-22T18:42:52.286Z","avatar_url":"https://github.com/zweifisch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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```\n\n## from config\n\n```python\nconf = dict(\n    db_host='localhost',\n    db_port='2345'\n)\n\nc.config(conf)\n\n@c.register(db)\ndef get_db(host, port):\n    assert host == conf.host\n    assert port == conf.port\n```\n\ncomponent registration in config\n\n```python\nconf = dict(\n    cache='redis:Redis',\n    cache_host='localhost',\n    cache_port='2345'\n)\n\nc.config(conf)\n\nc.cache.set('key', 'value')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Fslack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzweifisch%2Fslack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Fslack/lists"}