Hi
Instead of Ebean ORM I'm using Spring Data. It enables me to create repositories and inject them intro controllers and perform database operations. The problem that I have is, how to inject repository (or anything else) into form?
I have a situation where users enters an email and I want to validate if the email exists in the database or not. I think the proper way is to do this in the form. Currently I'm solving this in 2 ways:
1. creating an extra method validateEmail(UserRepository ...) and calling this method after I completed binding and validating form in controller. It works, but it's very clumsy, I can forget to add it, and it adds extra code to the controller.
2. By accessing repository with Play.current().global().getControllerInstance(UserRepository.class);. Again, it works but it's untestable and kinda hacky.
My question is - is there a proper way to do it? Or should I actually do this checking in a service and populate form errors in case of an error?