On Sat, 04 Jan 2014 16:03:11 GMT, Sergei Nosov wrote:

Hi!

Recently, I've discovered the inject functionality in vibe.d and I find it pretty neat. It allows to systematize the way aliases are pulled down to the diet templates.

However, it has a limitation.

Consider the authentication sample from the doc

(...)

What TODO hides could be a request to a database. So, one needs somehow to access the DB object inside authInjector.

The preferable solution, I believe, would be to have authCheck a member function of some class which has a db object as a member. But that's impossible with the current inject implementation since you need 'this' to call authCheck.

Could someone advice on how to approach the problem? (Making db object global will work, but is not very pretty)

Wouldn't it work if all of those functions would be class members instead of global functions. I'd assume that it would then be possible to use an alias to another member function, as the this of the calling scope would be used (in a kind of ugly, implicit way).

But generally, alias parameters and member functions unfortunately don't mix well. And DMD 2.065 even got a little worse with what operations it accepts on such aliases...

Oh another potential possibility: Pass the object on which authCheck will be called as an Aliases parameter and use mixin localAliases!(0, Aliases); to make it accessible and call the method on it.