In Play 2.5, the function Messages.get
was deprecated but we could still use it. The recommandation was to go all the way with injection.
I have done this everywhere I could (controller, service, etc.) but there is still places where a static function is needed. For example, I have a custom exception called InvalidEntityException
which override the getLocalizedMessage
.
@Override
public String getLocalizedMessage() {
return String.format(Messages.get("error.entity.invalid"), type.name(), entityId);
}
Since it's an override function, I can't pass the object for translation. And since it's an exception class, I can't inject it neither.
This is just an example, I have the same problem with Models. Models can't be injected because they are retrieve using Ebean. But I have functions like validate()
that throws some custom message that needs to be translated. In this case, I could pass the object for translation as a parameter but it seems wrong.
Any help would be appreciated.