Additional injected implicit parameter group in routers

(Ɓukasz) #1

Since Play 2.4 we are able to use InjectedRouteGenerator, combining this awesome feature with PathBindable and QueryStringBindable in routing, Play is very typesafe and heavily reduce validation boilerplate.

Unfortunately both PathBindable and QueryStringBindable implicit have to be statically reached via Scala implicit resolution mechanic. This constraint became very annoying at writing any bindable which depends on some initial configuration. A good example is having a custom class for URI but we want to validate URIs hostname according to some whitelist.

But with the generator we have now, we are unable to use those type of bindable. At least without loading configuration outside Application or depending Play.current with older versions.

The proposition is to add another optional parameter group marked as implicit to generated routes. This list could depend only on some sbt key, same as importRoutes.

This feature is fully backward compatible. With default set to empty list route generator should produce exactly same code as original one.

This allows use configuration depending bindable in routes without relying on global state. It is an unintrusive and optional feature which would increase support for DI in routes.

What do you think Play team? I may prepare some proof of concept but before contributing guideline advise ask on forum.