Skip to content

Container::call() should allow to define dependencies a la AngularJS #239

@mnapoli

Description

@mnapoli

Just like in AngularJS we can do:

angular.controller('MyController', ['$scope', 'dep1', 'dep2', function($scope, dep1, dep2) {
  // ...
}]);

It would be great to be able to explicitly ask for dependencies:

$container->call(['db.host', 'db.port', function ($host, $port) {
    // ...
}]);

Currently Container::call() guesses the objects to inject using type-hints, but this doesn't always work. By using AngularJS's pattern it's already well known and it solves the problem.

That could also be used (if #197 happens) in DI\factory too:

    'db' => DI\factory(['db.host', 'db.port', function ($host, $port) {
        return new Db($host, $port);
    }]);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions