hentai icon indicating copy to clipboard operation
hentai copied to clipboard

How implement repository without Spring Data?

Open macg20 opened this issue 1 year ago • 3 comments

Hi.Could you explain how to implement FilmRepository without SpringDataJpa and InMemory? Should FilmRepository be public then? Should the implementation FilmRepository then be in the infrastructure package? How can I do this while keeping the current package structure and package scope? Could you give an example?

macg20 avatar Jul 07 '22 18:07 macg20

Assuming you want to write a wrapper over some primitive tech (like JdbcTemplate or whatever), I'd just implement it directly in the same file. Just like InMemoryRepository. I know, religious zealots will say right away that this is infrastructure, and therefore should be down in the infra package (thus requiring Repo interface to become public), but I'm agnostic and pragmatic - I give no damn about religion. Everyone understands that Repo is infra, but limiting visibility by package scope is more important (and easy to get wrong). In fact I have implemented my own version of production ready repos exactly this way (for example to handle thread pools in non-reactive driver with subsribeOn). Worked like a charm, nobody made any mistakes with that for the next 3 years in 2 companies (so no problems for 7 years at least). But then again, I'm agnostic and pragmatic. I wouldn't be able to do that in a highly religious environment.

jakubnabrdalik avatar Jul 07 '22 18:07 jakubnabrdalik

Thank you for your answer!

macg20 avatar Jul 12 '22 15:07 macg20

Tangential to the topic but... I have made a compromise in some cases where repositories where already coded and tested in a different module. What I did in that case was to mock the repositories. It worked well for my use case of very loosely coupled microservices that just read events and trigger repo calls/create other events.

corlaez avatar Aug 08 '22 22:08 corlaez