The Play web framework allows injecting a list of "filters" to do common processing on requests (gzip, cors, logging, etc.)
package play.api
trait BuiltInComponents {
...
lazy val httpFilters: Seq[EssentialFilter] = Nil
<stuff that uses httpFilters>
...
}
I would like to have a common set of these filters (and other things).
package example
import play.api.BuildInComponents
trait MyCommonComponents extends BuiltInComponents {
...
override lazy val filters = Seq(
wire[Filter1],
wire[Filter2],
wire[Filter3]
)
...
}
Which can be used by subclasses
package example.foo
import example.MyCommonComponents
trait MyFooComponents extends MyCommonComponents {
...
}
Or added to by subclasses
package example.bar
import example.MyCommonComponents
trait MyBarComponents extends MyCommonComponents {
...
override lazy val filters = super.filters :+ wire[Filter4]
...
}
Things I have tried
- The code above. Can't use
super
with a lazy val. - Changing
httpFilters
todef
. Needs to be a stable value due to BuiltInComponents - Adding
lazy val httpFilters = filters
anddef filters: Seq[EssentialFilter] = ...
and then overridingfilters
as appropriate. Macwire complains about ambiguous types.
What can I do to achieve the optionally appended list of filters?
I probably don't get your scenario but what's wrong with simple
or this
Why do you want to override your
lazy val
instead of the basehttpFilters
that seem to be designed exactly to be overridden.