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
Inject未赋值identifier时,特殊情况下,对应的namespace会错误,导致找不到该属性。 #1277
Conversation
将`midway`生成的`schedule`注册进`egg`的`schedule`中。确保`schedule`可以被找到,避免只能通过`agent.schedule.closed`的方式才能关停`schedule`,而导致所有`schedule`都关闭。
这个最新的那个 mr 可能已经修了。 |
另外,不要再使用字符串引入组件。 |
试试新版本是否还有问题。 |
新版本可以了 |
那么 @Inject('cache:cacheManager')
cache; 这个的字符串参数还能用么? |
当前版本还可以,2.x 里可以继续用,3.x 还在考虑,作为一个兼容的话应该也可以,不过尽可能推进使用 class 作为类型,这样定义也有了。 |
那以后组件中的 namespace 的价值就不大了吧 |
对,虽然逻辑里会慢慢弱化 namespace 但是还是会作为排错的字段信息存在 |
又发现了一个新的问题。还是在发布包的情况下。 import {
Inject,
Controller,
Provide,
Get
} from "@midwayjs/decorator";
import { DemoService } from "../service/demo";
@Provide()
@Controller('/')
export class DemoController {
@Inject()
ctx;
@Inject() // 这样注入,demoService中的ctx为undefined
demoService: DemoService;
@Inject('DEMO:demoService')// 这样注入,demoService中的ctx才有值
demoService;
@Get('/test')
async test () {
await this.demoService.execute()
}
}
import { Provide, Inject } from '@midwayjs/decorator';
import { Context } from 'egg';
@Provide()
export class DemoService {
@Inject()
ctx: Context
async execute(): Promise<any> {
console.log(this.ctx)
}
} |
像是是在组件的情况下请求作用域对象没找到的样子 |
@roy2an 我模拟不出来,有没有具体的 repo case? |
我一会儿发个repo |
|
已定位,开始修复 |
@roy2an 试试2.13.1 |
好的 |
貌似npm各节点还没有更新。晚点再看看。 |
我的错。。。现在好了 |
测试了。已OK。 |
以引用 @midwayjs/axios 为例
如果将整个component发布成包的形式进行调用,系统会报错。报错如下:
httpService的namespace变成了WX。
Checklist
npm test
passesAffected core subsystem(s)
@midwayjs/core
@midwayjs/decorator
Description of change
在savePropertyInject函数中,为metadata中加入新的属性originDesign,存放inject属性对应的类型。并在restoreDefinition函数中根据originDesign值查询正确的identifier。