What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hey! I know that an instance of `\Symfony\Component\HttpFoundation\Request` can be injected into Yv

U0310RKK9U7 Posts: 5 🧑🏻‍🚀 - Cadet

Hey! I know that an instance of \Symfony\Component\HttpFoundation\Request can be injected into Yves’ controller action method. I know also that a path parameter can be also injected into controller action method. Is there a way to use constructor- or method-injection for the services needed in controller? Or using factory is the only way to get required dependencies into Yves controller?


  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 🪐 - Explorer

    The Request passed into a controller action is the current request and should not be used as a service, but only to get access to the content of the current request (e.g.: query parameters).
    Controllers in Spryker are not services like in Symfony, they are but they can't be modified to inject additional dependencies, that's why dependencies are retrieved via factory. The reason therefore is the core/project/code bucket inheritance logic in Spryker that comes with a locator that find's the right controller automatically.

  • U0310RKK9U7
    U0310RKK9U7 Posts: 5 🧑🏻‍🚀 - Cadet

    Thank you, Alberto! I just needed to be sure that using factory is the only and true Spryker way to use dependencies in controllers.

  • UQ958DA4U
    UQ958DA4U Posts: 232 🧑🏻‍🚀 - Cadet

    @U0310RKK9U7 Controllers have an overridable initialize() method.

    I like using it to only having to resolve for dependenceis exactly once.

  • U0310RKK9U7
    U0310RKK9U7 Posts: 5 🧑🏻‍🚀 - Cadet

    That’s nice! Thank you, @UQ958DA4U