-
Notifications
You must be signed in to change notification settings - Fork 8
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
[WIP] 带参数的类注入 #3
Comments
@JerrysShan 帮忙看看这个目前可以实现不 |
如果参数是可以注入的类型,目前可以通过这种形式传递参数
|
不过也考虑过在 |
这种形式有个问题是,参数必须是 Injectable class,假如是纯参数好像没法处理,比如一个可变的 string |
我现在的做法是给一个 init 方法,拿到实例后手动调用下 init 方法将参数传入,不知道有没有办法在 injection 这个类库中做一些更好的处理 |
这里不仅仅局限于 通过 |
这样看起来有冲突,对于 |
举个例子: @Injectable({
id: 'handle',
scope: ScopeEnum.EXECUTION
});
class HandleRequest {
constructor(req, res) {
this.req = req;
this.res = res;
}
}
http.createServer((req, res)=> {
const handle = container.get('handle'); // 这里的 req 和 res 有没有啥时机可以传进去
}); 如果把参数放到 |
一起看下这里怎么处理比较好吧 |
@whxaxes 要不一起看看这个有没有优雅一些的实现呢 |
这个可以的啊,元数据都是自己设的,只是你在 |
这里建议给 |
这样可以使得 pipeline 重大部分场景无需显式访问内置 context 对象,所有需要的 execution 属性全都通过 Inject 来进行使用 |
需求
每个 Execution 生命周期中实例化
Foo
时如何通过 container 传入构造函数需要的参数,比如:The text was updated successfully, but these errors were encountered: