Does Nette duplicate or reuses services?
Notice: This thread is very old.
- meridius
- Member | 34
Suppose I have this code:
services:
- MyService
- IMyEntityFactory
class MyEntity extends \Nette\Object {
public function __construct(MyService $myService) {
...
};
}
interface IMyEntityFactory {
/** @return MyEntity */
public function create();
}
...
/** @var IMyEntityFactory */
private $myEntityFactory;
...
$a = $this->myEntityFactory->create();
$b = $this->myEntityFactory->create();
The question is: How many instances of
MyService
will be created?
- David Grudl
- Nette Core | 8227
Each create()
creates new instance.
For reusing create interface with method get()
instead of
create()
.
- jiri.pudil
- Nette Blogger | 1030
Two instances of MyEntity will be created, but only one instance of MyService.