Skip to content

Instantly share code, notes, and snippets.

@koriym
Last active May 30, 2018 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koriym/88647b1029dd5275422d71ecf062c4e3 to your computer and use it in GitHub Desktop.
Save koriym/88647b1029dd5275422d71ecf062c4e3 to your computer and use it in GitHub Desktop.
Should dependency injector only do injections ?
<?php
// Should injections only do injections ?
// current - "get"Instance()
$injector = new Injector(new Bindings);
// get instance by interface name
$foo = $injector->getInstance(FooInterface::class);
// "injection" only - better ???
$injector = new Injector(new Bindings);
// create instance without dependent instance
$foo = (new \ReflectionClass(Foo::class))->newInstanceWithoutConstructor();
// dependency injection !!
$injector->inject($foo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment