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

关于 service 调用其他 service 时,不能用this #358

Closed
llqgit opened this issue May 18, 2016 · 1 comment
Closed

关于 service 调用其他 service 时,不能用this #358

llqgit opened this issue May 18, 2016 · 1 comment

Comments

@llqgit
Copy link

llqgit commented May 18, 2016

关于 service 调用其他 service 时,不能用this


比如我有一个发短信的service: msg_service
当我想用,user_service 调用他的时候,我需要这么写

think.service('msg_serivce', 'user');

而不能:

this.service('msg_service');

另一个问题:比如我在一个service 里,多个方法都需要调用 发短信的服务 msg_service


现在有两种方式:

1.每个方法里都写一句

let msg_service = new (think.service('msg_serivce', 'user'))();

2.在 init(...args) 的初始化方法里,写一句

this.msg_service = new (think.service('msg_serivce', 'user'))();

然后在每个方法里调用

this.msg_service.functions()

请问,有没有更好的解决方案,或者能够优化这部分的架构,因为这样操作觉得不舒服。。

ENV

Platform: mac

Node.js Version: 5.10

ThinkJS Version: 2.2

@welefen
Copy link
Member

welefen commented May 18, 2016

恩,后续版本里考虑添加 this.service 方法

@welefen welefen closed this as completed in a5e676e Aug 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants