-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add docs for plugin ExtensionGetter
- Loading branch information
Showing
4 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
docs/developer-guide/plugin/api-reference/server/extension-client.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
docs/developer-guide/plugin/api-reference/server/extension-getter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
title: 获取扩展实例 | ||
description: 了解如何在插件中获取扩展实例 | ||
--- | ||
|
||
Halo 提供了丰富的扩展点,而插件不仅可以实现扩展点,也可以通过使用 `ExtensionGetter` 来获取 Halo 或其他插件所提供的扩展实例。 | ||
|
||
关于插件如何实现扩展点的详细信息,请参考:[扩展点](./extension-points/index.md)。 | ||
|
||
```java | ||
public interface ExtensionGetter { | ||
|
||
/** | ||
* Get only one enabled extension from system configuration. | ||
* | ||
* @param extensionPoint is extension point class. | ||
* @return implementation of the corresponding extension point. If no configuration is found, | ||
* we will use the default implementation from application context instead. | ||
*/ | ||
<T extends ExtensionPoint> Mono<T> getEnabledExtension(Class<T> extensionPoint); | ||
|
||
/** | ||
* Get the extension(s) according to the {@link ExtensionPointDefinition} queried | ||
* by incoming extension point class. | ||
* | ||
* @param extensionPoint extension point class | ||
* @return implementations of the corresponding extension point. | ||
* @throws IllegalArgumentException if the incoming extension point class does not have | ||
* the {@link ExtensionPointDefinition}. | ||
*/ | ||
<T extends ExtensionPoint> Flux<T> getEnabledExtensions(Class<T> extensionPoint); | ||
|
||
/** | ||
* Get all extensions according to extension point class. | ||
* | ||
* @param extensionPointClass extension point class | ||
* @param <T> type of extension point | ||
* @return a bunch of extension points. | ||
*/ | ||
<T extends ExtensionPoint> Flux<T> getExtensions(Class<T> extensionPointClass); | ||
} | ||
``` | ||
|
||
### 示例 | ||
|
||
#### 单实例扩展点 | ||
|
||
对于单实例扩展点,例如 `SearchEngine` 扩展点,同一时间只能有一个实例被启用。要在插件中获取启用的搜索引擎扩展实例,可以使用以下代码: | ||
|
||
```java | ||
@Service | ||
@RequiredArgsConstructor | ||
public class SearchService { | ||
private final ExtensionGetter extensionGetter; | ||
|
||
Mono<SearchEngine> getSearchEngine() { | ||
return extensionGetter.getEnabledExtension(SearchEngine.class) | ||
} | ||
} | ||
``` | ||
|
||
#### 多实例扩展点 | ||
|
||
对于多实例扩展点,例如 `ReactiveNotifier` 扩展点,可以同时启用多个实例。要在插件中获取所有启用的通知器扩展实例,可以使用以下代码: | ||
|
||
```java | ||
@Service | ||
@RequiredArgsConstructor | ||
public class NotificationService { | ||
private final ExtensionGetter extensionGetter; | ||
|
||
Flux<ReactiveNotifier> getNotifiers() { | ||
return extensionGetter.getEnabledExtensions(ReactiveNotifier.class) | ||
} | ||
} | ||
``` |
2 changes: 1 addition & 1 deletion
2
docs/developer-guide/plugin/api-reference/server/reverseproxy.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/developer-guide/plugin/api-reference/server/role-template.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters