- Drupal 8 Module Development
- Daniel Sipos
- 236字
- 2021-07-02 15:45:15
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 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).
- R語言數(shù)據(jù)分析從入門到精通
- Pandas Cookbook
- JavaScript+jQuery開發(fā)實戰(zhàn)
- C語言程序設(shè)計
- Python高級編程
- Full-Stack Vue.js 2 and Laravel 5
- Monitoring Elasticsearch
- Eclipse Plug-in Development:Beginner's Guide(Second Edition)
- PHP+MySQL網(wǎng)站開發(fā)項目式教程
- Java EE 8 Application Development
- 深入理解Android:Wi-Fi、NFC和GPS卷
- HTML5+CSS3 Web前端開發(fā)技術(shù)(第2版)
- Swift 4從零到精通iOS開發(fā)
- Kubernetes進階實戰(zhàn)
- Simulation for Data Science with R