官术网_书友最值得收藏!

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).

Many Drupal 8 core service definitions can be found inside the core.services.yml file located in the root /core folder. So, if you are ever looking for service names to use, your best bet is to look there. Additionally, core modules also have service definitions inside their respective *.services.yml files. So, make sure that you also check there.
主站蜘蛛池模板: 缙云县| 西昌市| 葫芦岛市| 陆良县| 扎囊县| 婺源县| 彰武县| 台北市| 正安县| 射洪县| 呼和浩特市| 金山区| 忻州市| 太白县| 进贤县| 行唐县| 芒康县| 东台市| 津南区| 大足县| 滨海县| 吉林市| 荔浦县| 福州市| 桂林市| 澄城县| 比如县| 澳门| 霍林郭勒市| 永年县| 商都县| 永登县| 元江| 荣成市| 彭山县| 百色市| 宜昌市| 全南县| 诏安县| 内江市| 新乡市|