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

拦截器中无法注入TypeORM Model吗? #3289

Open
minefujiko9293 opened this issue Sep 26, 2023 · 2 comments
Open

拦截器中无法注入TypeORM Model吗? #3289

minefujiko9293 opened this issue Sep 26, 2023 · 2 comments

Comments

@minefujiko9293
Copy link

我对于Main控制器写了个拦截器,完成用户登录的日志功能,却发现@InjectEntityModel注入的实体为undefined ,如下代码,打印出来的this.m_NW_SYS_LOG_OF_LOGIN 为 undefined
image

image
这是为什么呢

@minefujiko9293
Copy link
Author

目前改写成以下代码已完成功能,但是还想知道拦截器中注入失败的原因,因为中间件使用 @InjectEntityModel没问题,但是拦截器却不行,中间件不也是单例吗(PS:中间件为路由中间件)?
image

之前我是使用中间件来完成该功能的,中间件中@InjectEntityModel没问题。
image

@czy88840616
Copy link
Member

可能和执行时机有关,拦截器类的初始化时机非常靠前,早于 typeorm 的model初始化之前了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants