h******b 发帖数: 6055 | 1 我看过很多书/文章知道angular的controller应该是slim的,甚至不应该有business
logic。
但个人感觉来说,我用controller直接http.get, 直接在controller里用underscore.
js来sort/group/filter我的$scope数据, 感觉写起来流畅很多。大大降低了angular的
learning curve。 我始终不明白同样一个getusers(), 放controller里我只需要写一
遍,放service里我还得在controller里reference,何必呢?
如果好几个controller分享一个service我可以理解。 但最少个人小项目里,基本上
是一个界面一个api。 |
a9 发帖数: 21638 | 2 怎么方便怎么来
【在 h******b 的大作中提到】 : 我看过很多书/文章知道angular的controller应该是slim的,甚至不应该有business : logic。 : 但个人感觉来说,我用controller直接http.get, 直接在controller里用underscore. : js来sort/group/filter我的$scope数据, 感觉写起来流畅很多。大大降低了angular的 : learning curve。 我始终不明白同样一个getusers(), 放controller里我只需要写一 : 遍,放service里我还得在controller里reference,何必呢? : 如果好几个controller分享一个service我可以理解。 但最少个人小项目里,基本上 : 是一个界面一个api。
|
l**********n 发帖数: 8443 | 3 it seems that you haven't written large angular projects
【在 h******b 的大作中提到】 : 我看过很多书/文章知道angular的controller应该是slim的,甚至不应该有business : logic。 : 但个人感觉来说,我用controller直接http.get, 直接在controller里用underscore. : js来sort/group/filter我的$scope数据, 感觉写起来流畅很多。大大降低了angular的 : learning curve。 我始终不明白同样一个getusers(), 放controller里我只需要写一 : 遍,放service里我还得在controller里reference,何必呢? : 如果好几个controller分享一个service我可以理解。 但最少个人小项目里,基本上 : 是一个界面一个api。
|
g*****g 发帖数: 34805 | 4 书都是按照可扩展可维护的角度来写的。典型的三层架构里,controller在front tier
,你把商业逻辑写进去,不好重用。你个人写完就扔的项目当然可以怎么快怎么来。
【在 h******b 的大作中提到】 : 我看过很多书/文章知道angular的controller应该是slim的,甚至不应该有business : logic。 : 但个人感觉来说,我用controller直接http.get, 直接在controller里用underscore. : js来sort/group/filter我的$scope数据, 感觉写起来流畅很多。大大降低了angular的 : learning curve。 我始终不明白同样一个getusers(), 放controller里我只需要写一 : 遍,放service里我还得在controller里reference,何必呢? : 如果好几个controller分享一个service我可以理解。 但最少个人小项目里,基本上 : 是一个界面一个api。
|
p*****2 发帖数: 21240 | 5 大实话
tier
【在 g*****g 的大作中提到】 : 书都是按照可扩展可维护的角度来写的。典型的三层架构里,controller在front tier : ,你把商业逻辑写进去,不好重用。你个人写完就扔的项目当然可以怎么快怎么来。
|
h******b 发帖数: 6055 | 6 个人文科生土鳖思维上来说,model如果是rest还有数据库本身都比较容易理解。
比如我call个/api/users,拿到一串json,用controller倒腾一下就直接上界面了。作
为前台我一直以为/api/users就是model/service。
angular一直让我绕不过弯来的就是call这个/api/users,教科书上是应该在service/
factory里call的。
那么最大优势就是不同controller可以共享一个service/factory了。 可是我本来就
可以从不同controller来call/api/users。如果我需要共享一个getuserbyid,我会直
接在rest里面提供。 何必搞angular service呢?
tier
【在 g*****g 的大作中提到】 : 书都是按照可扩展可维护的角度来写的。典型的三层架构里,controller在front tier : ,你把商业逻辑写进去,不好重用。你个人写完就扔的项目当然可以怎么快怎么来。
|
h******b 发帖数: 6055 | 7 的确没有,文科生半路出家。 主要是希望能有写MVP,prototype的能力。
【在 l**********n 的大作中提到】 : it seems that you haven't written large angular projects
|
g*****g 发帖数: 34805 | 8 The service/factory you talk about is not service layer in 3 tier sense. It'
s an aggregation/adaptor layer. Backend services are typically more fine-
grained and you want a more coarse-grained facade then you can do it here.
Say if you have backend services, one to store a user account, one to send
an email. You can assemble these two in this layer and call from various
controllers.
【在 h******b 的大作中提到】 : 个人文科生土鳖思维上来说,model如果是rest还有数据库本身都比较容易理解。 : 比如我call个/api/users,拿到一串json,用controller倒腾一下就直接上界面了。作 : 为前台我一直以为/api/users就是model/service。 : angular一直让我绕不过弯来的就是call这个/api/users,教科书上是应该在service/ : factory里call的。 : 那么最大优势就是不同controller可以共享一个service/factory了。 可是我本来就 : 可以从不同controller来call/api/users。如果我需要共享一个getuserbyid,我会直 : 接在rest里面提供。 何必搞angular service呢? : : tier
|
s***o 发帖数: 2191 | 9 If I want to have a "transaction" on this aggregation layer, what would be a
good way to implement it?
It'
【在 g*****g 的大作中提到】 : The service/factory you talk about is not service layer in 3 tier sense. It' : s an aggregation/adaptor layer. Backend services are typically more fine- : grained and you want a more coarse-grained facade then you can do it here. : Say if you have backend services, one to store a user account, one to send : an email. You can assemble these two in this layer and call from various : controllers.
|
c*********e 发帖数: 16335 | 10 service是singleton.这个很重要,意味着你在整个project里只有一个。
【在 h******b 的大作中提到】 : 个人文科生土鳖思维上来说,model如果是rest还有数据库本身都比较容易理解。 : 比如我call个/api/users,拿到一串json,用controller倒腾一下就直接上界面了。作 : 为前台我一直以为/api/users就是model/service。 : angular一直让我绕不过弯来的就是call这个/api/users,教科书上是应该在service/ : factory里call的。 : 那么最大优势就是不同controller可以共享一个service/factory了。 可是我本来就 : 可以从不同controller来call/api/users。如果我需要共享一个getuserbyid,我会直 : 接在rest里面提供。 何必搞angular service呢? : : tier
|
x**n 发帖数: 461 | 11 This is typically because you don't have sufficient experiences to realize
the benefit of single responsibility. |
g*****g 发帖数: 34805 | 12 Try to keep it in one backend service, that's most reliable. When not
possible, don't use distributed transaction, use monitoring and alert.
a
【在 s***o 的大作中提到】 : If I want to have a "transaction" on this aggregation layer, what would be a : good way to implement it? : : It'
|