Code Monkey home page Code Monkey logo

Comments (9)

hiqsol avatar hiqsol commented on May 25, 2024 3

@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.

viktorprogger avatar viktorprogger commented on May 25, 2024 1

"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.

fcaldarelli avatar fcaldarelli commented on May 25, 2024

"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.

viktorprogger avatar viktorprogger commented on May 25, 2024

@FabrizioCaldarelli sorry, didn't see you're in YiiSoft team. I thought you're just one more newbie, shame on me.

from docs.

viktorprogger avatar viktorprogger commented on May 25, 2024

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.

viktorprogger avatar viktorprogger commented on May 25, 2024

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.

viktorprogger avatar viktorprogger commented on May 25, 2024

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.

fcaldarelli avatar fcaldarelli commented on May 25, 2024

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.

hiqsol avatar hiqsol commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.