plugin_services: cleanup

This commit is contained in:
Yann Cébron 2019-03-07 18:22:50 +01:00
parent 4ab29528a4
commit c9632283b6

View File

@ -2,9 +2,7 @@
title: Plugin Services
---
The *IntelliJ Platform* provides the concept of _services_.
A _service_ is a plugin component loaded on demand, when your plugin calls the `getService` method of the [ServiceManager](upsource:///platform/core-api/src/com/intellij/openapi/components/ServiceManager.java) class.
A _service_ is a plugin component loaded on demand when your plugin calls the `getService` method of the [ServiceManager](upsource:///platform/core-api/src/com/intellij/openapi/components/ServiceManager.java) class.
The *IntelliJ Platform* ensures that only one instance of a service is loaded even though the service is called several times. A service must have an implementation class which is used for service instantiation. A service may also have an interface class which is used to obtain the service instance and provides API of the service. The interface and implementation classes are specified in the `plugin.xml` file.
@ -12,7 +10,7 @@ The *IntelliJ Platform* offers three types of services: _application level_ serv
## How to Declare a Service?
To declare a service, you can use the following extension points in the IDEA core:
To declare a service, you can use the following extension points in the IntelliJ Platform:
* `applicationService`: designed to declare an application level service.
* `projectService`: designed to declare a project level service.
@ -22,9 +20,9 @@ To declare a service, you can use the following extension points in the IDEA cor
1. In your project, open the context menu of the destination package and click *New* (or press <kbd>Alt</kbd>+<kbd>Insert</kbd>).
2. In the *New* menu, choose *Plugin DevKit* and click *Application Service*, *Project Service* or *Module Service* depending on the type of service you need to use.
3. In the dialog box that opens, you can specify service interface and implementation, or just a service class if you uncheck *Separate interface from implementation* checkbox.
3. In the dialog box that opens, you can specify service interface and implementation, or just a service class if you uncheck *Separate interface from implementation* check box.
The IDE will generate new Java interface and class (or just a class if you unchecked *Separate interface from implementation* checkbox) and register the new service in `plugin.xml` file.
The IDE will generate new Java interface and class (or just a class if you unchecked *Separate interface from implementation* check box) and register the new service in `plugin.xml` file.
> **Note** Declaring a service via *New* context menu is available since version **2017.3**.
@ -34,14 +32,16 @@ To clarify the service declaration procedure, consider the following fragment of
```xml
<extensions defaultExtensionNs="com.intellij">
<!-- Declare the application level service -->
<applicationService serviceInterface="Mypackage.MyApplicationService" serviceImplementation="Mypackage.MyApplicationServiceImpl" />
<applicationService serviceInterface="Mypackage.MyApplicationService"
serviceImplementation="Mypackage.MyApplicationServiceImpl" />
<!-- Declare the project level service -->
<projectService serviceInterface="Mypackage.MyProjectService" serviceImplementation="Mypackage.MyProjectServiceImpl" />
<projectService serviceInterface="Mypackage.MyProjectService"
serviceImplementation="Mypackage.MyProjectServiceImpl" />
</extensions>
```
If `serviceInterface` isn't specified it's supposed to have the same value as `serviceImplementation`.
If `serviceInterface` isn't specified, it's supposed to have the same value as `serviceImplementation`.
## Retrieving a service