Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dg
Created August 19, 2014 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dg/00ae93962614dfcb7d41 to your computer and use it in GitHub Desktop.
Save dg/00ae93962614dfcb7d41 to your computer and use it in GitHub Desktop.
DI: Symfony versus Nette
services:
newsletter_factory: NewsletterFactory
newsletter_manager: @newsletter_factory::get(@templating)
parameters:
newsletter_manager.class: NewsletterManager
newsletter_factory.class: NewsletterFactory
services:
newsletter_factory:
class: "%newsletter_factory.class%"
newsletter_manager:
class: "%newsletter_manager.class%"
factory_service: newsletter_factory
factory_method: get
arguments:
- "@templating"
@dg
Copy link
Author

dg commented Aug 19, 2014

@gondo
Copy link

gondo commented Mar 2, 2016

you don't have to use parameters in Symfony, that is optional

@Richtermeister
Copy link

That's actually a super-neat syntax. Any downsides? Should be possible to adopt this in Symfony, no? Are there already any efforts on the way?

@theofidry
Copy link

Let's rectify symfony one:

services:
    newsletter_factory:
        class: NewsletterFactory

    newsletter_manager:
        class: NewsletterManager
        factory: ['@newsletter_factory', get]
        arguments:
            - '@templating'
  • you don't have to use parameters for your classes
  • you're using a deprecated factory declaration

@TomasVotruba
Copy link

TomasVotruba commented Jan 1, 2019

Random visitor passing by in 2019...

# symfony
services:
    App\:
        resource: '../'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment