The Dependency Injection component is one of the central pieces of any Symfony applications since version 2.0. Starting this winter, it has gained many new features that were needed to build the new Symfony 4 experience around Flex. While used extensively in core, can you leverage them in your own apps? Can you create a lazy iterator in Yaml? A scoped service locator? Configure auto-configuration? During this talk, I'll tell you about the new tags, interfaces or annotations that allow building powerful services. The goal: making your apps always more expressive, thus maintainable.

Comments

Comments are closed.

Timo Bakx at 14:17 on 17 Nov 2017

Great talk, too bad there was more information than time. I'd love to hear more about the changes in the DI component.
Speaker was clear and excited to talk. It was a pleasure to listen to this talk.

Jeff Sacco at 14:21 on 17 Nov 2017

This is how a talk should be. He knew his audience, clear and concise slides, great speaker.

Great talk.
He really could explain the changes in the DI component.
Too bad there wasn't more time.

Nicolas Grekas (Speaker) at 16:57 on 17 Nov 2017

> If you have 2 services implementing same interface, why do you suggest to wire them thru the interface but not directly? This way you don't need to put an alias

but your code should not target wiring! your code should target SOLID principles! which means following the LSP principle, so coding against abstractions.

> Is it possible to use wildcard path specs in the config files (i.e. ../src/*/Controller)?

Yes, the entry is a glob pattern

> What is the overhead of using autowire vs getting services from container? Because it must involve Reflection...

None, Symfony's container is compiled

> Do the defaults apply to imported files as well?

no, defaults apply only to the current file

> Who want some beer tonight?

sure ;)

> What is the difference between service locator and container?

using Symfony v4 specific definitions to answer thuis question: a container is The container, ie the object that holds all services.
A service locator is a container that knows only about a short list of predeclared services (could be with a different id)

> Is it possible to extend the config of individual services with Annotations? Like setting one explicitly to public and/or add an alias

Using annotations to define DI config is not possible (it has been rejected several times as ppl/core-team were not convinced by it, but that's never a definitive answer ;-) )

> How to register a service from vendor/ to di?

using regular DI configuration. But if a vendor needs a DI config, then make that config a Flex recipe so that the vendor package is made easy to install

> Do we have to write down service spec when creating factory pattern classes or DI v4 will automatically do the work for us?

yes, factories cannot be automated. But if you think of Doctrine repositories, v1.8 of the DoctrineBundle provides a new base class repository that works with autowiring.

> Can I use patterns or wildcards in the resources param in services yml?

yes you can! (and it's recursive when defining services)

> How are tagged services injected into class? Array in constructor?

as iterator objects (RewindableGenerator class in DI component, but your should always use the "iterable" type hint, never this class directly)

> We have an additional sf event dispatcher in sulu when using autoconfig would the subscribers be called in both dispatcher. how could this be fixed?

advanced and new question, needs custom response, I don't what to give bad answer yet, community discussion needed

> When extending AbstractController is it really necessary implementing ServiceSubscriberInterface? Actually AbstractController already implements it

Correct, that was for the demo :)

Steve Winter at 20:08 on 17 Nov 2017

Excellent presentation from the man behind the machine - next time please give him a (much) bigger room and twice as long so that we can get right into the details and the demos.

Good talk about the new DI component by its author. The depth of the presentation was alright for me, since he described all the new features or changes that have been made compare to the previous DI component. It barely fit into the time slot, but it was alright.

When I will upgrade, I'll have to get into all the details by myself anyway.

Good presentation skills! Thanks!

Good presentation of new features. Liked sli.do idea as well.

Awesome new features/talk !

Andreas B. at 08:14 on 21 Nov 2017

Changes in the DIC are great, as was the presentation by Nicolas. Unfortunately, there wasn't enough time to go into detail for most of the changes, but given that it's an advanced track that's ok: you get an overview and then look up what you're interested in your own time.

Jose Monagas at 01:30 on 23 Nov 2017

One of the best improvements in Symfony nowadays and perfectly explained by Nicolas. Congratulations!