Rails service objects vs lib classes

前端 未结 2 389
长情又很酷
长情又很酷 2021-01-30 13:33

Short version: when should I put something into app/services instead of into lib/.

I\'ve been going down the service objects route recently, but I realised that

2条回答
  •  萌比男神i
    2021-01-30 13:58

    This is how I tend to think about code that goes in lib/:

    • It is not coupled to my app's domain models.
    • It can be reused on other projects.
    • It can potentially become its own gem. Thus, putting it in lib/ is the first step in that direction.

    Services:

    • They tend to know a decent amount about the inner workings of domain models.
    • Perform work that is specific to business domain in my app.
    • Tend to be coupled to specific models.

提交回复
热议问题