huntc / play-spring-data-jpa

2 stars 29 forks source link

Inject repository into other classes #2

Open FrEaKmAn opened 10 years ago

FrEaKmAn commented 10 years ago

Hi

Thank you for this example. Even though there are few major problems with using your example in real-life projects, I'm still sticking with it. My question is how could I include repository into other classes beside controller? For example forms (LoginForm)?

  1. final Form form = Form.form(LoginForm.class).bindFromRequest();
  2. public class LoginForm { @Required @Email public String email;

    @Required public String password; public String next;

    @Autowired private PersonRepository personRepository;

...

personRepository is always null...any ideas?

FrEaKmAn commented 10 years ago

Actually I got it working by calling

this.personRepository = Play.current().global().getControllerInstance(PersonRepository.class);

but I find it a bit hackish..