Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义插件怎么注入 #114

Closed
yinshanhu opened this issue Apr 12, 2023 · 4 comments
Closed

自定义插件怎么注入 #114

yinshanhu opened this issue Apr 12, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@yinshanhu
Copy link

在此输入你需要反馈的 Bug 具体信息(Bug in Detail):

1.使用的是eggjs框架,egg-redis不符合我的使用场景,于是通过addSingleton注册了自己的插件,名称为:‘redis’。确认注册是成功的。

2.代码里使用时,注入的方式:
import type { Redis } from 'ioredis';
@Inject()
private readonly redis: Redis;

3、报错:
framework.EggPrototypeNotFound: Object redis not found in LOAD_UNIT:......................................非关键信息省略..........
code: TEGG_EGG_PROTO_NOT_FOUND
serialNumber: EGG_PROTO_NOT_FOUND

还请大佬帮忙解答。

可复现问题的仓库地址(Reproduction Repo)

Node 版本号:

v18.14.1

TEgg 版本号:

3.5.2

相关插件名称与版本号:

1

操作平台与版本号:

window11

@yinshanhu yinshanhu added the bug Something isn't working label Apr 12, 2023
@fengmk2
Copy link
Member

fengmk2 commented Apr 12, 2023

@yinshanhu
Copy link
Author

https://github.com/cnpm/cnpmcore/blob/master/app/infra/QueueAdapter.ts#L18 可以参考。

老哥,我参考的就是这个,这个用的官方egg-redis插件,我自定义插件就报错。

@WuWhite
Copy link

WuWhite commented May 6, 2023

自定义插件可以通过ctx带过去 @context() ctx: EggContext,

@killagu
Copy link
Contributor

killagu commented May 6, 2023

现在是通过 https://github.com/eggjs/tegg/blob/master/plugin/tegg/lib/EggAppLoader.ts#L109 这里遍历 context 上的 properties 来实现的。

如果插件不是通过 extends 来实现,就没法找到了。

@killagu killagu closed this as completed Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants