Skip to content

Argument Collection Details

cfchris edited this page Apr 19, 2013 · 6 revisions

The goal of Relaxation is to get the maximum use of your services with minimal interference. To that end, it will combine all of the different sources of parameters into a nice "ArgumentCollection" to call your service methods with.

In short, if I did my job right, the arguments your methods receive will just make sense™. If you're happy with that for now, you may choose not to read any further.

Argument Building Sequence

The following is the sequence that Relaxation uses to build the argument collection.

  1. Parameters are collected from all the various places.

  2. A variable is created with the following structure.

    var args = { "Payload": Payload, "ArgumentSources": { "DefaultArguments": DefaultArguments, /* (Optional) */ "FormScope": FormScope, "PathValues": PathValues, "Payload": Payload, "URLScope": URLScope } }

  3. The following scopes are appended in the following order with (overwrite false).

    Path values Body values (If it's a struct) URL scope Form scope Default arguments

Example

Given the following request, ...

HTTP POST to "/product/1?Testing=Foo"
Pattern match "/product/{ProductID}"
Form scope like:
	ProductID = 5
	ProductName = "Hot Sauce!"
	Price = "$5.99"
	User = "HoneyD"

... you would get the following argument collection to your service method.

{
	/* Always here. Empty in this case. */
	"Payload": {},
	/* Always here. Keys might be empty. */
	"ArgumentSources": {
		"URLScope": {
			"Testing": "Foo"
		},
		"FormScope": { 
			"ProductID": 5,
			"ProductName": "Hot Sauce!",
			"Price": "$5.99",
			"User": "HoneyD"
		},
		"PathValues": {
			"ProductID": 1
		},
		"Payload": {}
	},
	/* All keys from all arg sources. Appended in specific order. */
	"ProductID": 1, 				/* From Path */
	"ProductName": "Hot Sauce!",	/* From FORM */
	"Price": "$5.99",				/* From FORM */
	"Testing": "Foo",				/* From URL */
	"User": "HoneyD"				/* From FORM */
}

"Argument Sources" Argument

Your method will get all of the different sources of values in an "ArgumentSources" argument. This is helpful for diagnostics. It can also be useful in the case where the same parameter name is specified in multiple scopes.