문제

Imagine that you have a Grails projects with a great service layer and you want to make sure that your team only accesses the model through your services.

Is it easily possible to restrict the dynamic finders so that they can be still used from within the service (same package) but not outside?

I can imagine to overwrite them, but then they are also gone for the service...

도움이 되었습니까?

해결책

There isn't really an easy way to restrict where method calls can from. You could write a global AST transformation which looks for dynamic finder calls and disallows all of them that do not come from a service. If you are versed in writing AST transformations that wouldn't be prohibitively complicated but it isn't trivial. If you are not versed in writing AST transformations then I do not recommend taking this on as your first adventure in that space. To be honest, I don't recommend it either way, but it is an answer to your question. It can be done, but I wouldn't say that there is an easy way.

다른 팁

There is a grails plugin for CodeNarc, which does static analysis and can fail the build if a developer commits a violation.

There are several built-in Grails Rules, but they don't do what you want. You would need to create a custom rule. See this screencast.

The closest one is probably GrailsDomainWithServiceReference It checks that Grails Domain classes do not have Service classes injected.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top