yiisoft / yiisoft/injector

InjectorDependence

Open
#33 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status:under discussion
Dominant language
PHP
Stars
94
Forks
17
Avg merge
56m
Merged PRs (30d)
1

Description

$injector->addDependenceInjector(
    new DependenceInjector()
        ->withParamClass(TestInterface::class)
        ->withParamName('testA')
        ->referenceTo(TestA::class)
);

$injector->addDependenceInjector(
    new DependenceInjector()
        ->withClass(MethodСlass::class)
        ->withParamClass(TestInterface::class)
        ->referenceTo(TestB::class)
);

$injector->addDependenceInjector(
    new DependenceInjector()
        ->withClass(MethodСlass::class)
        ->withMethod('actionTest')
        ->withParamName('testA')
        ->referenceTo('containerID')
);

// The following code is just for example. I believe that you need to make
// dependencies not by number, but by parameter name.
$injector->addDependenceInjector(
    new DependenceInjector()
        ->withClass(MethodСlass::class)
        ->withMethod('__construct')
        ->withParamPos(1)
        ->referenceTo('containerID')
);

// Not singleton
$injector->addDependenceInjector(
    new DependenceInjector()
        ->withParamClass(TestInterface::class)
        ->handler(function(ContainerInterface $container, Param $param) {
            $paramClass = $param->getParamClass();
            $paramName = $param->getParamName();
            $paramPos = $param->getParamPos();
            $methodClass = $param->getMethodClass();
            $methodName = $param->getMethodName();
            ...
            // We can return the singleton from the container.
            // We can create an object and place it in a container for reuse.
    })
);

$defaultDependenceInjectors = [
    new DependenceInjector()->handler(function(ContainerInterface $container, Param $param) {
        return $container->get($param->getParamClass());
    }),
    new DependenceInjector()->handler(function(ContainerInterface $container, Param $param) {
        return $container->get($param->getParamClass() . '$' . $param->getParamName());
    }),
];

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue body centers on DependenceInjector, Param, addDependenceInjector(), and handler callbacks; no files or tests are named. Start by tracing those entry points in the repository and determine how dependencies are currently matched. Done requires an agreed design and implementation for the proposed parameter-based dependency resolution and handler behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.