I have seen dependency injection written the following way when creating something like a Controller or Service layer in MVC Play apps (using javax.inject.Inject
or com.google.inject.Inject
):
class Controller @Inject()(thing: Something) { ... }
And I have also seen it written like this:
class Controller @Inject()(val thing: Something) { ... }
Is there any benefit to writing one over the other? What's the difference?
If I were to hazard a guess, I'd think that one instantiates a new instance of that parameter where the other just reuses the same instance of whichever parameter was passed in, but I wouldn't know which is which and I don't know whether that's even right or not.