Comments (9)
@viktorprogger is right. You should have something like this:
public function __construct($id, $module, \yii\authclient\clients\GitHub $githubClient)
{
parent::__construct($id, $modjule);
$this->githubClient = $githubClient;
}
from docs.
"Autowiring" is a phenomenon when dependencies can be automatically passed to the constructor or another method. It is a responsibility of a framework you're using, not DI container. I guess you're using Yii2 which don't know autowiring.
I'm happy to say yii3 already has this feature. Hope we'll see a stable release of this major update this year 👍
from docs.
"Autowiring" is a phenomenon when dependencies can be automatically passed to the constructor or another method. It is a responsibility of a framework you're using, not DI container. I guess you're using Yii2 which don't know autowiring.
I refer to Yii3. My question is about what is the recommendation.
@rob006 What do you think?
from docs.
@FabrizioCaldarelli sorry, didn't see you're in YiiSoft team. I thought you're just one more newbie, shame on me.
from docs.
It is a responsibility of a framework you're using, not DI container
Either I'm wrong or it's just not about this DI container. It is really responsible for autowiring.
Diving deeper into the code...
from docs.
As I see a web request results into a controller action through \yii\base\Module::createControllerByID
which calls $this->app->createObject
. So, the controller must be created within the DI container which resolves your dependencies.
I think you need to provide a bit more code to debug.
from docs.
I think you just need to keep your controller's parent declaration in your mind: public function __construct($id, $module)
. Try to write so and make your dependency to be the third parameter.
from docs.
Ok, but is there a shared solution that we can suggest? Just to have the same approach everywhere in the code.
I indeed don't like some of this and some of that in the code.
from docs.
Yes. That's what was mentioned somewhere as "wider use of DI".
But, you are right, it should be stressed out stronger.
from docs.
Related Issues (20)
- Running yii3 on subfolder with IIS 10 HOT 19
- Adopt to router changes HOT 2
- Feature: Add deploy instrument integration HOT 4
- Do not mention default values in PHPDoc HOT 1
- Consider using conventional comments for code review HOT 1
- Have rules about resolving discussions / conversations in code review HOT 4
- Chain calls must be put on separate lines HOT 14
- Add Related packages section HOT 2
- update CODE_OF_CONDUCT.md links
- update yii site links
- update links
- broken links
- Add Rule and Rule Handler to glossary
- Add common PHPStorm config
- Document explicit `null` type hint HOT 5
- Configure max line length
- Code style summary to discuss and configure HOT 4
- Automatically add line breaks for long lines in Markdown HOT 1
- Automatically detect broken links
- Link to the next chapter where it makes sense
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.