D For A Web Developer
Dicebot via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 30 05:38:30 PDT 2014
On Wednesday, 30 April 2014 at 10:01:51 UTC, Rikki Cattermole
wrote:
>> Why can't stand-alone annotated function be a valid route?
>> Route is pretty much method + url + handler and first two can
>> be inferred by convention in many cases (as done in
>> vibe.web.rest & Co).
>
> The only way I know of that doesn't result in a container is
> registerRoutes!"mymodule"; Instead of registerRoute!MyRoute;
Well you need to specify this only once with root module (usually
app.d) supplied as a parameter. You can query all imported
modules recursively from it.
> Now if I could get access to a list of all the modules and
> hence all routes at CTFE then that wouldn't be an issue. Same
> deal for models.
This can't be done with same guarantees as runtime reflection
because of separate compilation. Requirement to transitively to
import everything from root module is necessary. I don't see it
much of a burden though.
> There is some benefits of having a container for routes however.
> Being able to add UDAs to that group of routes. I.e. Don't
> generate javascript, give them a name/grouping.
> While its possible without it, its a bit more distinct.
There are definitely several benefits of having aggregated
compile-time known list of routes. Actually I have added it as
one of examples for my DConf talk just yesterday :) This list,
however, can possibly be built automatically via reflection
provided single root entry point.
I think good flexible framework should provide user both options
and infer as much as possible by convention.
More information about the Digitalmars-d
mailing list