{"id":37079467,"url":"https://github.com/eyaldror/di_container","last_synced_at":"2026-01-14T09:37:04.541Z","repository":{"id":62568076,"uuid":"286440159","full_name":"eyaldror/di_container","owner":"eyaldror","description":"Dependency Injection Container - Full featured, flexible and fluent IoC solution for Python","archived":false,"fork":false,"pushed_at":"2022-05-08T13:17:30.000Z","size":43,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-25T06:58:01.650Z","etag":null,"topics":["dependency-injection","inversion-of-control","inversionofcontrol","ioc","ioc-container","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/di-container/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eyaldror.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-10T10:06:29.000Z","updated_at":"2025-02-09T06:25:50.000Z","dependencies_parsed_at":"2022-11-03T16:31:01.982Z","dependency_job_id":null,"html_url":"https://github.com/eyaldror/di_container","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/eyaldror/di_container","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyaldror%2Fdi_container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyaldror%2Fdi_container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyaldror%2Fdi_container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyaldror%2Fdi_container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eyaldror","download_url":"https://codeload.github.com/eyaldror/di_container/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eyaldror%2Fdi_container/sbom","scorecard":{"id":388742,"data":{"date":"2025-08-11","repo":{"name":"github.com/eyaldror/di_container","commit":"8782d802f3bf9cea5465ce77f04dcf967620b434"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 1/18 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T17:17:39.680Z","repository_id":62568076,"created_at":"2025-08-18T17:17:39.681Z","updated_at":"2025-08-18T17:17:39.681Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28416120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:38:59.149Z","status":"ssl_error","status_checked_at":"2026-01-14T08:38:43.588Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dependency-injection","inversion-of-control","inversionofcontrol","ioc","ioc-container","python"],"created_at":"2026-01-14T09:37:03.869Z","updated_at":"2026-01-14T09:37:04.532Z","avatar_url":"https://github.com/eyaldror.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Dependency Injection Container\n### Full featured, flexible and fluent IoC solution for Python\n\n#### PyPi\ndi_container can be installed from [PyPi](https://pypi.org/project/di-container/). \n\n#### The Code\n\n##### Basics:\nTypes, callables and values can be registered into a container and bound to either a dependency type, or a name.\nRegistration is independent of dependency order: A dependency can be registered after the dependent type, as long as they are both registered before resolving.\n```python\nfrom di_container.container import Container\n\ncontainer = Container(name='container')\n\ncontainer.register_callable(main).to_name('main_func')\ncontainer.register_value(app_config['logging']['log_path']).to_name('log_path')\ncontainer.register_type(FileLogger).to_type(ILogger)\n```\n\n##### Multiplicity:\nTypes and callables can be registered as `Instantiation.Singleton` (default), or as `Instantiation.MultiInstance`.\n```python\nfrom di_container.container import Container, Instantiation\n\ncontainer = Container(name='container')\n\ncontainer.register_callable(ConnectionFactory.new_udp_connection, instantiation=Instantiation.MultiInstance).to_type(IConnection)\n```\n\n##### Type checks:\nRegistering `to_type` type checks against the given dependency type. When registering `to_name`, an optional type can be given, in order to make the same check.\nIf the check fails, a `TypeError` is raised.\n```python\nfrom di_container.container import Container\n\ncontainer = Container(name='container')\n\ncontainer.register_value(app_config['network']['http_port']).to_name('port', int)\n```\n\n##### Manual assignment:\nType initializers and callables can have some, or all, of their arguments assigned values explicitly.\nThe rest will be resolved at resolve time.\n```python\nfrom di_container.container import Container, Instantiation\n\ncontainer = Container(name='container')\n\ncontainer.register_callable(ConnectionFactory.new_udp_connection, instantiation=Instantiation.MultiInstance).to_type(IConnection).with_params(host='localhost', port=12345)\n```\n\n##### Resolving order:\nResolving a registered type, or name, will attempt to resolve any needed arguments for type initializers, or callables, recursively.\nFirst, with values given in `with_params`, second, with arguments' type annotations (please use them 🙂), and then, with declared default values.\n\nWhen a dependency is registered `to_name`, it cannot be automatically inferred by type annotation.\nA container's default behavior is to use an argument's name to lookup a `to_name` registration as a last attempt to resolve an argument.\nThis behavior can be changed if it's deemed to be too risky, and dependency names can be assigned explicitly when needed, using `with_name_bindings`.\n\nThe full order of resolution attempts for a parameter is:\n1. Given value, in the form of `with_params(param=value)`. The value of param will be the given value.\n1. Name binding, in the form of `with_name_bindings(param='name_binding')`. The value of param will be the resolution of the name 'name_binding'.\n1. Type annotation. If the parameter has a type annotation (type hint), then the value of param will be the resolution of this type.\n1. If `param_names_as_bindings` is `True`, The container will attempt to resolve the param name itself.\n   If successful, the value of param will be the resolution of the parameter's name.\n1. Lastly, if a default value is defined for the parameter, it will be used. The value of param will be its default value.\n   If, however, `prefer_defaults` is `True` in calling `resolve_type` or `resolve_name`,\n   the default value will be used if no explicit value or binding was given (No `with_params` or `with_name_bindings` for that parameter),\n   instead of trying to resolve the type annotation or parameter name.\n\n```python\nfrom di_container.container import Container, Instantiation\n\ncontainer = Container(name='container', param_names_as_bindings=False)\n\ncontainer.register_callable(ConnectionFactory.new_udp_connection, instantiation=Instantiation.MultiInstance).to_type(IConnection).with_name_bindings(host='host_ip', port='port')\ncontainer.register_value(app_config['network']['ip']).to_name('host_ip', str)\ncontainer.register_value(app_config['network']['http_port']).to_name('port', int)\n```\n\n##### Sub-containers:\nSub-containers can help when writing several packages, or sub-systems, or just to organize a large amount of dependencies.\nThe resolving process will try to resolve from the current container and if no match is found, will try to resolve using each sub-container (and its sub-containers recursively) in the order they were added.\nContainers are initialized with names for identification in error messages.\n```python\nfrom di_container.container import Container\n\nbase_container = Container(name='base')\n# register config values and core classes\nbase_container.register_value(app_config['logging']['log_path']).to_name('log_path')\nbase_container.register_value(app_config['database']['database_url']).to_name('database_url', str)\nbase_container.register_type(FileLogger).to_type(ILogger)\nbase_container.register_type(NoSqlDatabase).to_type(IDatabase)\n\nmain_container = Container('main')\n# register main class and entry point\nmain_container.register_callable(main).to_name('main_function').with_name_bindings(main_manager='main_class')\nmain_container.register_type(MainManager).to_name('main_class').with_name_bindings(internal_comm='int_comm', external_comm='ext_comm')\n\ncomm_container = Container('comm')\n# register communication classes\ncomm_container.register_type(UdpCommunicator).to_name('int_comm', ICommunicator)\ncomm_container.register_type(HttpCommunicator).to_name('ext_comm', ICommunicator)\n\n# setting sub containers\ncomm_container.add_sub_container(base_container)\nmain_container.add_sub_container(base_container)\nmain_container.add_sub_container(comm_container)\n\n# activating the main function\nmain_container.resolve_name('main_function')\n```\n\n#### To Do\nSome features that are being considered:\n1. Configuration registration.\n1. Binding to members of registered items.\n1. Registration of collections of values.\n1. Display of dependency tree (forest).\n\n#### More\n* An [example](http://github.com/eyaldror/di_container/tree/master/example) is available in the git repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feyaldror%2Fdi_container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feyaldror%2Fdi_container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feyaldror%2Fdi_container/lists"}