Commit fa70be2f authored by nanahira's avatar nanahira

fix inject and add isGlobal

parent 860b1e6e
Pipeline #6160 passed with stages
in 1 minute and 21 seconds
......@@ -83,6 +83,8 @@ Koishi-Nest 的配置项和 Koishi 配置项一致,参照 [Koishi 文档](http
* `options` Koishi 插件配置。等同于 `ctx.plugin(plugin, options)`
* `select` 插件选择器,定义插件的作用上下文。定义参照 [Koishi 文档](https://koishi.js.org/v4/guide/plugin/context.html#%E5%9C%A8%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E4%B8%AD%E4%BD%BF%E7%94%A8%E9%80%89%E6%8B%A9%E5%99%A8) 的写法。
* `isGlobal`: `boolean` 默认 `false` 。指示 Koishi-Nest 模块是否应被注册为全局模块。 **异步配置该项应写入异步配置项中。** 关于全局模块请参考 [Nest.js 文档](https://docs.nestjs.cn/8/modules?id=%e5%85%a8%e5%b1%80%e6%a8%a1%e5%9d%97)
插件的使用可以参考 [Koishi 文档](https://koishi.js.org/v4/guide/plugin/plugin.html)
## 注入 Koishi 实例
......
{
"name": "koishi-nestjs",
"version": "1.0.33",
"version": "1.0.34",
"description": "Koishi.js as Nest.js Module",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
......
......@@ -34,7 +34,11 @@ export function PluginDef<T extends Plugin>(
return { plugin, options, select };
}
export interface KoishiModuleOptions extends App.Config {
export interface WhetherGlobalOption {
isGlobal?: boolean;
}
export interface KoishiModuleOptions extends App.Config, WhetherGlobalOption {
usePlugins?: KoishiModulePlugin<Plugin>[];
loggerPrefix?: string;
}
......@@ -44,7 +48,8 @@ export interface KoishiModuleOptionsFactory {
}
export interface KoishiModuleAsyncOptions
extends Pick<ModuleMetadata, 'imports'> {
extends Pick<ModuleMetadata, 'imports'>,
WhetherGlobalOption {
useExisting?: Type<KoishiModuleOptionsFactory>;
useClass?: Type<KoishiModuleOptionsFactory>;
useFactory?: (
......
......@@ -99,6 +99,7 @@ export class KoishiModule implements NestModule {
return {
module: KoishiModule,
providers: [{ provide: KOISHI_MODULE_OPTIONS, useValue: options }],
global: options.isGlobal,
};
}
......@@ -106,7 +107,11 @@ export class KoishiModule implements NestModule {
return {
module: KoishiModule,
imports: options.imports,
providers: this.createAsyncProviders(options),
providers: [
...this.createAsyncProviders(options),
...(options.extraProviders || []),
],
global: options.isGlobal,
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment