简体   繁体   中英

Laravel Ioc container in out of Laravel

I've created a listener in Laravel 5.2.I which depends on Requests object instances via Ioc container. How can I do that? Say I've created foo class that depends on bar class in Laravel. How can I get automatic resolution through Laravel Ioc ?

Considering that any class can be built through the IoC. It can be as simple as

$foo = app(Foo::class);

This would dependency inject Bar if it is type hinted correctly in the constructor of Foo AND both Foo and Bar have no other dependencies that can't be resolved by IoC.

If you have dependencies that can't be resolved by reflection, you will need to let the IoC know how to construct them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM