xp-forge / inject

Dependency injection for the XP Framework
0 stars 0 forks source link

Add inject.ConfiguredBindings class which reads from a properties file #6

Closed thekid closed 9 years ago

thekid commented 9 years ago

Examples

Binding to a class:

scriptlet.Session=com.example.session.FileSystem

Binding to an instance, passing parameters:

scriptlet.Session=com.example.session.MemCache("tcp://localhost:11211")

Binding primitives:

string[api-key]="6c51b0830a9ab74cc8cbe"
bool[use-api]=true

Using namespaces:

[com.example.session]
scriptlet.Session=Redis("user:pass@localhost")

Using ConfiguredBindings for the Injector.

$inject= new Injector(new ConfiguredBindings('bindings.ini'));
$session= $inject->get('scriptlet.Session');
$apiKey= $inject->get('string', 'api-key');

Inside an XPCLI:

use util\PropertyAccess;

class Test extends \util\cmd\Command {
  private $inject;

  #[@inject(name= 'bindings')]
  public function useInjector(PropertyAccess $prop) {
    $this->inject= new Injector(new ConfiguredBindings($prop));
  }

  // ....
}