- Drupal 8 Module Development
- Daniel Sipos
- 237字
- 2021-07-02 12:22:39
What is a service?
A service is an object that gets instantiated by a Service Container and is used to handle operations in a reusable way, for example, performing calculations and interacting with the database, an external API, or any number of things. Moreover, it can take dependencies (other services) and use them to help out. Services are a core part of the dependency injection (DI) principle that is commonly used in modern PHP applications and in Drupal 8.
If you don't have any experience with these concepts, an important thing to note is also that they are globally registered with the service container and instantiated only once per request. This means that altering them after you requested them from the container means that they stay altered even if you request them again. In essence, they are singletons. So, you should write your services in such a way that they stay immutable, and most of the data they need to process is either from a dependency or passed in from the client that uses it (and does not affect it).
- Java語言程序設計
- Visual Basic 6.0程序設計計算機組裝與維修
- 大學計算機基礎實驗教程
- Magento 2 Theme Design(Second Edition)
- Mastering JBoss Enterprise Application Platform 7
- Learning ArcGIS for Desktop
- 焊接機器人系統操作、編程與維護
- Java EE核心技術與應用
- C和C++游戲趣味編程
- ElasticSearch Cookbook(Second Edition)
- Mastering C++ Multithreading
- Vue.js 3應用開發與核心源碼解析
- Java Web從入門到精通(第2版)
- Hands-On Robotics Programming with C++
- TypeScript圖形渲染實戰:2D架構設計與實現