{"id":20103151,"url":"https://github.com/dotkernel/dot-dependency-injection","last_synced_at":"2025-07-08T21:36:06.982Z","repository":{"id":243229460,"uuid":"811784597","full_name":"dotkernel/dot-dependency-injection","owner":"dotkernel","description":"Dependency Injection (DI)  handler","archived":false,"fork":false,"pushed_at":"2025-03-14T15:26:44.000Z","size":92,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"1.0","last_synced_at":"2025-04-09T10:27:13.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docs.dotkernel.org/dot-dependency-injection/","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/dotkernel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-07T09:45:20.000Z","updated_at":"2025-04-03T22:10:19.000Z","dependencies_parsed_at":"2024-06-07T13:52:08.556Z","dependency_job_id":"9e7fb7ed-b5aa-49c3-b7d8-34b8cfe64479","html_url":"https://github.com/dotkernel/dot-dependency-injection","commit_stats":null,"previous_names":["dotkernel/dot-dependency-injection"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-dependency-injection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-dependency-injection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-dependency-injection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotkernel%2Fdot-dependency-injection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotkernel","download_url":"https://codeload.github.com/dotkernel/dot-dependency-injection/tar.gz/refs/heads/1.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252648539,"owners_count":21782405,"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":"2024-11-13T17:34:28.021Z","updated_at":"2025-05-06T08:31:09.574Z","avatar_url":"https://github.com/dotkernel.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dot-dependency-injection\n\n`dot-dependency-injection` is Dotkernel's dependency injection service.\n\nBy providing reusable factories for service and repository injection, it reduces code complexity in projects.\n\n## Documentation\n\nDocumentation is available at: https://docs.dotkernel.org/dot-dependency-injection/.\n\n## Badges\n\n![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-dependency-injection)\n![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-dependency-injection/1.2.0)\n\n[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/issues)\n[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/network)\n[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/stargazers)\n[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/blob/1.0/LICENSE.md)\n\n[![Build Static](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/continuous-integration.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/continuous-integration.yml)\n[![codecov](https://codecov.io/gh/dotkernel/dot-dependency-injection/graph/badge.svg?token=DayAoD2Oj6)](https://codecov.io/gh/dotkernel/dot-dependency-injection)\n[![docs-build](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/docs-build.yml/badge.svg)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/docs-build.yml)\n[![PHPStan](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/static-analysis.yml)\n\n## Installation\n\nInstall `dot-dependency-injection` by running the following command in your project directory:\n\n```shell\ncomposer require dotkernel/dot-dependency-injection\n```\n\nAfter installing, register `dot-dependency-injection` in your project by adding the below line to your configuration\naggregate (usually: `config/config.php`):\n\n```php\nDot\\DependencyInjection\\ConfigProvider::class,\n```\n\n## Usage\n\n### Using the AttributedServiceFactory\n\nYou can register services in the service manager using `AttributedServiceFactory` as seen in the below example:\n\n```php\nreturn [\n    'factories' =\u003e [\n        ServiceClass::class =\u003e AttributedServiceFactory::class,\n    ],\n];\n```\n\n### NOTE\n\n\u003e You can use only the fully qualified class name as the service key\n\nThe next step is to add the `#[Inject]` attribute to the service constructor with the service FQCNs to inject:\n\nuse Dot\\DependencyInjection\\Attribute\\Inject;\n\n```php\n#[Inject(\n    App\\Srevice\\Dependency1::class,\n    App\\Srevice\\Dependency2::class,\n    \"config\",\n)]\npublic function __construct(\n    protected App\\Srevice\\Dependency1 $dep1,\n    protected App\\Srevice\\Dependency2 $dep2,\n    protected array $config\n) {\n}\n```\n\nThe `#[Inject]` attribute is telling `AttributedServiceFactory` to inject the services specified as parameters.\nValid service names should be provided, as registered in the service manager.\n\nTo inject an array value from the service manager, you can use dot notation as below\n\nuse Dot\\DependencyInjection\\Attribute\\Inject;\n\n```php\n#[Inject(\n    \"config.debug\",\n)]\n```\n\nwhich will inject `$container-\u003eget('config')['debug'];`.\n\n### NOTE\n\n\u003e Even if using dot notation, `AttributedServiceFactory` will check first if a service name exists with that name.\n\n### Using the AttributedRepositoryFactory\n\nYou can register doctrine repositories and inject them using the `AttributedRepositoryFactory` as below:\n\n```php\nreturn [\n    'factories' =\u003e [\n        ExampleRepository::class =\u003e AttributedRepositoryFactory::class,\n    ],\n];\n```\n\nThe next step is to add the `#[Entity]` attribute in the repository class.\n\nThe `name` field has to be the fully qualified class name.\n\nEvery repository should extend `Doctrine\\ORM\\EntityRepository`.\n\n```php\nuse Api\\App\\Entity\\Example;\nuse Doctrine\\ORM\\EntityRepository;\nuse Dot\\DependencyInjection\\Attribute\\Entity;\n\n#[Entity(name: Example::class)]\nclass ExampleRepository extends EntityRepository\n{\n}\n```\n\n\u003e Dependencies injected via the`#[Entity]`/`#[Inject]` attributes are not cached\n\n\u003e Injecting dependencies into property setters are not supported\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotkernel%2Fdot-dependency-injection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotkernel%2Fdot-dependency-injection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotkernel%2Fdot-dependency-injection/lists"}