3
I have a question about how best to implement some services with the Spring Rest, but I couldn’t find the material for this case:
Let’s say I have a launch service (Lancamentoservice). This service makes the launch, updates the balance and charges a fee. Soon, I have injected the repositories Lancamentorepository, Saldorepository and Tarifarepository.
In addition to this service, it would also have services to serve, transfer, etc., and all of these would need to make a launch, in addition to other things. To do this I’m injecting the Lancamentoservice within each of these services.
However, even if I call a service on Saqueservice, for example, that would not need to make launches, the LancamentoService is "loaded", along with all its repositories.
Is that right? If someone has a better practice or some reference material I really appreciate it.
I understood, so I was not far from ideal. Taking advantage then: the use of a generic Repository would bring some performance benefit?
– Rodrigo Nunes
Is not Repository generic. Today, following your example, you inject directly into the class
LancamentoService
the repositories of the actions a release may have. That’s not a good idea. The best is that each of these repositories have your own service (i.e., for example, you would create aSaldoService
and within it would inject theSaldoRepository
, create a public method, for example: calculate Aldo(), and in the classLancamentoService
, you inject thatSaldoService
(and not theSaldoRepository
, as you mentioned in your example) newly created and calls the methodcalcularSaldo()
.– StatelessDev
Beauty. Thank you very much!
– Rodrigo Nunes