{"id":15916886,"url":"https://github.com/kodcube/dependency-injection","last_synced_at":"2025-04-03T11:25:45.875Z","repository":{"id":57007970,"uuid":"63515809","full_name":"kodcube/dependency-injection","owner":"kodcube","description":"Dependency Injection Container","archived":false,"fork":false,"pushed_at":"2017-03-08T04:07:21.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-09T00:47:18.080Z","etag":null,"topics":["container-interop","dependency-injection","php7"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/kodcube.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":"2016-07-17T05:08:09.000Z","updated_at":"2022-02-12T14:05:33.000Z","dependencies_parsed_at":"2022-08-21T13:10:48.317Z","dependency_job_id":null,"html_url":"https://github.com/kodcube/dependency-injection","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodcube%2Fdependency-injection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodcube%2Fdependency-injection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodcube%2Fdependency-injection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodcube%2Fdependency-injection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kodcube","download_url":"https://codeload.github.com/kodcube/dependency-injection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246991183,"owners_count":20865603,"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":["container-interop","dependency-injection","php7"],"created_at":"2024-10-06T18:06:16.195Z","updated_at":"2025-04-03T11:25:45.823Z","avatar_url":"https://github.com/kodcube.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dependency Injection Container / Service Locator / Object Builder\n\nThis package is Recursive Dependency Injection Container (DiC) / Service Locator / Object Builder\n\nIt has been designed to take it's dependency configuration map as part of it's construction,\nso rather than setting up all the dependencies at runtime they can be loaded from a configuration file or files.\n\nSo as long as you can create an array, the configuration is injected at construction.\n\n### Main Features \n* Build a Service/Object/Class based on a class name or alias\n* Build a Class/Object that requires other dependencies\n* Cache built Service/Object/Class for reuse in other classes (e.g. Database Connections)\n* Build a Object/Class with a combination of passed and required dependencies\n* Recursive Object Creation\n\n\n### Limitations\n* Does not inject dependencies for methods other than __constructor \n* Does not inject dependencies for setters\n\n### Requirements\n* PHP 7\n* container-interop/container-interop\n\n\n\n\n* [Usage](#usage) - _Basic usage examples_\n  * [Create Container](#create-container)\n  * [Get Object from Container](#get-object-from-container)\n  * [Check if Alias\\Class Exists in Container](#check-if-aliasclass-exists-in-container)\n  * [Make Object](#make-object)\n* [Methods](https://github.com/kodcube/dependency-injection/wiki/Container#methods)\n* [Aliases](https://github.com/kodcube/dependency-injection/wiki/Aliases-\u0026-Service-Locators)\n* [AutoWiring](https://github.com/kodcube/dependency-injection/wiki/Autowiring)\n\n[Configuration Examples](https://github.com/kodcube/dependency-injection/wiki/Configuration)\n\n## Usage\n\n### Create Container\n\n``` PHP\n$di = new KodCube\\DependencyInjection\\Container();\n\nor\n\n$di = new KodCube\\DependencyInjection\\Container($config);\n\nor\n\n$di = new KodCube\\DependencyInjection\\Container([\n  'MyAlias' =\u003e 'Vendor\\Package\\Class',\n  'Vendor\\Package\\Interface' =\u003e 'Vendor\\Package\\Class'\n])\n\n``` \n\n### Get Object from Container using an alias\n\nUsing Alias\n``` PHP\n$object = $di-\u003eget('MyAlias');\n\nor \n\n$object = $di('MyAlias');\n\nor\n \n$object = $di-\u003eMyAlias(); \n```\n\nUsing Class Name \n``` PHP\n$object = $di-\u003eget('Vendor\\Package\\Class');\n\nor \n\n$object = $di('Vendor\\Package\\Class');\n```\n\nUsing Interface Name (requires dependency map) \n``` PHP\n$object = $di-\u003eget('Vendor\\Package\\Interface');\n\nor \n\n$object = $di('Vendor\\Package\\Interface');\n```\n\n### Check if Alias\\Class Exists in Container\n``` PHP\nAlias\n$object = $di-\u003ehas('MyAlias');\n\nClass\n$object = $di-\u003ehas('Vendor\\Package\\Class');\n```\n\n### Make Object\nMake a object using the DiC using passed arguments. \n\nThis will also take advantage of the autowiring properties of the container.\n\nNote: Objects created with additional arguments are not cached by the container.\n\n``` PHP\n$object = $di-\u003emake('Vendor\\Package\\Class','argument1','argument2');\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodcube%2Fdependency-injection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkodcube%2Fdependency-injection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodcube%2Fdependency-injection/lists"}