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

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

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.
主站蜘蛛池模板: 兰西县| 丹凤县| 新巴尔虎左旗| 兰溪市| 民乐县| 临漳县| 高清| 泽普县| 大荔县| 蓝田县| 罗江县| 平武县| 远安县| 灯塔市| 棋牌| 万山特区| 剑河县| 桦甸市| 阿勒泰市| 昌黎县| 临城县| 灵川县| 樟树市| 宜兰市| 察雅县| 女性| 大足县| 昆山市| 盐池县| 静安区| 隆安县| 大荔县| 霍州市| 景德镇市| 平潭县| 班戈县| 抚宁县| 阿坝| 鄂托克旗| 广丰县| 盐城市|