vibe.d beta banner
get vibe.d

Asynchronous I/O that doesn’t get in your way, written in D

Struct InjectedParams

Makes the variable aliases passed to one of the injectors of the inject!() template accessible to the local function.

struct InjectedParams(Aliases) ;


void authInjector(alias Next, Aliases...)(HTTPServerRequest req, HTTPServerResponse res)
	string userinfo;
	// TODO: fill userinfo with content, throw an Unauthorized HTTP error etc.
	Next!(Aliases, userinfo)(req, res);

void somethingInjector(alias Next, Aliases...)(HTTPServerRequest req, HTTPServerResponse res)
	// access the userinfo variable:
	if( InjectedParams!Aliases.userinfo.length == 0 ) return;

	// it's also possible to declare a pseudo-
	// variable like this to access the parameters:
	InjectedParams!Aliases params;
	if( params.userinfo == "peter" )
		throw Exception("Not allowed!")

	Next!(Aliases)(req, res);

Sönke Ludwig


© 2012 RejectedSoftware e.K.


Subject to the terms of the MIT license, as written in the included LICENSE.txt file.