2

Without a DI container, you would normally do something like this:

$foo = (new FooBuilder)
->setA('a')
->setB('b')
->build();

// where $foo becomes an instance of Foo class

How do you register/containerize something like that in Aura.Di?

IMB
  • 15,163
  • 19
  • 82
  • 140

1 Answers1

2

Found it. For those who care, it's lazyGetCall()

E.g., If you have something like this:

$foo = (new FooBuilder)
->setA('a')
->setB('b')
->build();

You can containerize it like this:

$builder = new \Aura\Di\ContainerBuilder;
$di = $builder->newInstance();
$di>setters['FooBuilder']['setA'] = 'a';
$di>setters['FooBuilder']['setB'] = 'b';
$di->set('FooBuilder', $di->lazyNew('FooBuilder'));
$di->set('Foo', $di->lazyGetCall('FooBuilder', 'build'));

You can then call it elsewhere like this: $fooInstance = $di->get('Foo');

IMB
  • 15,163
  • 19
  • 82
  • 140