Symfony Tutorial Container Service 6 – Setter Injection



In previous tutorials in this Symfony container course we injected our dependencies via the service constructor. In this tutorial we are going to use setter methods to do this.

Using setter method injection is very useful especially if you are using a factory design pattern or if you have optional dependencies that you wish to set after the service has been instantiated.

We are going to continue using our validation classes that we built in previous tutorials and inject configuration when retrieving these classes from the Symfony service container.

Code can be found on github:
https://github.com/pfwd/how-to-code-well-tutorials

If you would like to join me and other web developers on Discord then signup to be a Patron. Other benefits to being a patron include gaining early access to future tutorials, joining a newsletter and getting discounts on programming courses and resources.
You will also be supporting continuation and growth of the channel.

Become a Patron: http://bit.ly/2wK4F0U

======== RECOMMENDED PROGRAMMING RESOURCES ========

Manning programming books and courses: http://bit.ly/2BIrExp

PHP Books:
http://howtocodewell.net/shop/books/php

PHP Hosting from Cloudways:
http://bit.ly/2CB4mWD

======== MY PROGRAMMING COURSES ========

Docker in Motion: http://bit.ly/2vvz2sA
Skillshare courses: http://skl.sh/2gI33M5
Udemy courses: http://bit.ly/2iGhvIE

======== WEB HOSTING DEALS ========

Cloudways: http://bit.ly/2CKb79b = 20% off first 6 months
Digital Ocean: https://m.do.co/c/9d4641c62263 = $10 off
Linode: http://bit.ly/2CmoNq3

======== SUBSCRIBE TO THE NEWSLETTER ========

Join the Newsletter: http://bit.ly/2fPlG3v

======== FOLLOW ME ========

Blog: http://peterfisher.me.uk
Facebook: http://facebook.com/howtocodewell/
Instagram: http://instagram.com/howtocodewell/
Twitter: http://twitter.com/howToCodeWell
Pintrest: http://pinterest.co.uk/howtocodewell/
Twitch: http://twitch.tv/howtocodewell

======== MY CONFERENCE/USER GROUP TALKS ========

How to put your Docker image on a diet: http://bit.ly/2y5KMly
Using a framework or not? https://youtu.be/T8R3YTrqt6U

======== SUPPORT THE CHANNEL ========

Become a Patron: http://bit.ly/2hmVKwX
Donate: https://www.paypal.me/howToCodeWell
Help translate the videos: http://bit.ly/2iEyxXB

======== VIDEO SETUP ========

Nikon D5300 Camera: http://amzn.to/2u5jreD
Logitech HD Pro Webcam C920 http://amzn.to/2C5NNVJ
CRAPHY Photography Studio Lights: http://amzn.to/2BThzOc
Rode Procaster Microphone: http://amzn.to/2sH2WJ1
Rode VideoMic Pro: http://amzn.to/2vmNF0D
Zoom H4NPro: http://amzn.to/2kZrrvo

source