-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Way to use global #99
Comments
That would result in using it as service locator and that is exactly what we've tried to avoid. |
Hi, why not use delegate with a reflection class instead of injecting the entire container. Example: <?php declare(strict_types=1);
$container = new League\Container\Container;
// register the reflection container as a delegate to enable auto wiring
$container->delegate(
new League\Container\ReflectionContainer
);
$foo = $container->get(Acme\Foo::class);
var_dump($foo instanceof Acme\Foo); // true
var_dump($foo->bar instanceof Acme\Bar); // true
var_dump($foo->baz instanceof Acme\Baz); // true
var_dump($foo->bar->bam instanceof Acme\Bam); // true |
@rustamwin I think it's better to get container instance to where functions are declared and pass it there via |
Here you go: yiisoft/demo@af88e0b |
Is this a temporary solution? |
No, why? I want to make accessing container globally (except maybe these functions) a hard enough task so people won't abuse it without thinking. |
* Replaced the variable with the getter method. (#24) * Remove unused views * Update meta files * Tune config * Allow accessing container instance in globals.php See yiisoft/di#99 * ContectController fix mailer params (#28) * Added routes names and replaced static URL to dynamic (#29) * Use `auth` package (#30) * Config fix
What steps will reproduce the problem?
Getting container globally
What is the expected result?
this is useful for functions
e.g:
Container::getInstance()
What do you get instead?
Additional info
The text was updated successfully, but these errors were encountered: