Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Mastering Drupal 8

You're reading from   Mastering Drupal 8 An advanced guide to building and maintaining Drupal websites

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher Packt
ISBN-13 9781785885976
Length 456 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Authors (3):
Arrow left icon
Sean Montague Sean Montague
Author Profile Icon Sean Montague
Sean Montague
Chaz Chumley Chaz Chumley
Author Profile Icon Chaz Chumley
Chaz Chumley
William Hurley William Hurley
Author Profile Icon William Hurley
William Hurley
Arrow right icon
View More author details
Toc

Table of Contents (25) Chapters Close

Title Page
Credits
About the Author
Acknowledgments
About the Author
About the Reviewer
Customer Feedback
www.PacktPub.com
Preface
1. Developer Workflow FREE CHAPTER 2. Site Configuration 3. Managing Users, Roles, and Permissions 4. Content Types, Taxonomy, and Comment Types 5. Working with Blocks 6. Content Authoring, HTML5, and Media 7. Understanding Views 8. Theming Essentials 9. Working with Twig 10. Extending Drupal 11. Working with Forms and the Form API 12. RESTful Services 13. Multilingual Capabilities 14. Configuration Management 15. Site Migration 16. Debugging and Profiling

Working with dependency injection


Dependency injection is an example of an inversion of control software design pattern. Inversion of control is a principle that involves having a generic and reusable framework to make calls and delegate to more custom code. In Drupal 7, an example of this is the menu system. A request comes in and is matched to a route and then Drupal loads the module file and calls the appropriate function. Dependency injection specifically allows you to define when your class needs a dependency and have those needs fulfilled by the system.

When creating new functionality in Drupal 8, you write your dependencies into your class constructor and, when the system creates your class, they are passed into it.

A key advantage to using dependency injection is that you do not have to know how to instantiate the services that your class depends on. Take, for example, a simple database connection. In order to connect to the database you need the appropriate driver, username, password...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images