mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
plugin_services.md: clarify injecting Coroutine Scope
This commit is contained in:
parent
e4cfe8aeec
commit
4ec2775bac
@ -63,8 +63,10 @@ application/project [services](plugin_services.md) provided by a plugin.
|
||||
|
||||
### Service Scopes
|
||||
|
||||
The **Application Service** and **Project Service** scopes are bound to an application and project [service](plugin_services.md) lifetimes accordingly.
|
||||
They are children of the [](#intersection-scopes), which means that they are canceled when the application/project is closed or a plugin is unloaded.
|
||||
<snippet id="serviceScopes">
|
||||
|
||||
The **Application Service** and **Project Service** scopes are bound to an application and project [service](plugin_services.md#types) lifetimes accordingly.
|
||||
They are children of the [](coroutine_scopes.md#intersection-scopes), which means that they are canceled when the application/project is closed or a plugin is unloaded.
|
||||
|
||||
The service scope is provided to services via constructor injection.
|
||||
The following constructor signatures are supported:
|
||||
@ -75,6 +77,10 @@ The following constructor signatures are supported:
|
||||
Each service instance receives its own scope instance.
|
||||
The injected scopes' contexts contain [`Dispatchers.Default`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html) and [`CoroutineName(serviceClass)`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-name/).
|
||||
|
||||
See [](launching_coroutines.md#launching-coroutine-from-service-scope) for full samples.
|
||||
|
||||
</snippet>
|
||||
|
||||
## Using a Correct Scope
|
||||
|
||||
### Use Service Scopes
|
||||
|
@ -34,9 +34,6 @@ To improve startup performance, avoid any heavy initializations in the construct
|
||||
|
||||
Project/Module-level service constructors can have a [`Project`](%gh-ic%/platform/core-api/src/com/intellij/openapi/project/Project.java)/[`Module`](%gh-ic%/platform/core-api/src/com/intellij/openapi/module/Module.java) argument.
|
||||
|
||||
When using [](kotlin_coroutines.md), a distinct [Service Scope](coroutine_scopes.md#service-scopes) can be injected as parameter.
|
||||
See [](launching_coroutines.md#launching-coroutine-from-service-scope) for full samples.
|
||||
|
||||
> Using constructor injection of dependency services is deprecated (and not supported in [](#light-services)) for performance reasons.
|
||||
>
|
||||
> Other service dependencies must be [acquired only when needed](#retrieving-a-service) in all corresponding methods, e.g., if you need a service to get some data or execute a task, retrieve the service before calling its methods.
|
||||
@ -46,6 +43,12 @@ See [](launching_coroutines.md#launching-coroutine-from-service-scope) for full
|
||||
>
|
||||
{style="warning" title="Do not use Constructor Injection"}
|
||||
|
||||
##### Kotlin Coroutines
|
||||
|
||||
When using [](kotlin_coroutines.md), a distinct service [scope](coroutine_scopes.md) can be injected as parameter.
|
||||
|
||||
<include from="coroutine_scopes.md" element-id="serviceScopes"/>
|
||||
|
||||
## Light Services
|
||||
|
||||
A service not going to be overridden does not need to be registered in <path>[plugin.xml](plugin_configuration_file.md)</path> (see [](#declaring-a-service)).
|
||||
|
Loading…
x
Reference in New Issue
Block a user