Grails: Dynamically inject service in domain class

前端 未结 3 1225
独厮守ぢ
独厮守ぢ 2021-02-06 13:33

I need to inject a service based on domain property, so far I came up with the following:

ApplicationHolder.application.getServiceClass(\"package.${property}Serv         


        
3条回答
  •  臣服心动
    2021-02-06 13:55

    IMHO domain classes shouldn't contain logic at all (apart form the validators).

    In my projects I normally create a service for each domain class (e.g. UserService for class User) and I stick all the logic in there, even small bits in pieces that would normally be in the domain class.

    I think a lot of programmers coming from Java/C++ world tend to find this ugly, but it suits better the Grails architecture.

提交回复
热议问题