Using OpenRasta and given the following 2 handlers:
public class HelloWorldHandler1
{
public string GetHelloWorld(string test, string test2)
{
return "Hello.World!";
}
}
public class HelloWorldHandler2
{
public string GetHelloWorld(string test)
{
return "Hello.World!";
}
}
Configured as follows
ResourceSpace.Has.ResourcesOfType<Resource1>()
.AtUri("/{test}/{test2}")
.HandledBy<HelloWorldHandler1>();
ResourceSpace.Has.ResourcesOfType<Resource2>()
.AtUri("/Hello/{test}")
.HandledBy<HelloWorldHandler2>();
If I GET /first/example
then HelloWorldHandler1.GetHelloWorld
is called with parameters first
and example
as expected.
If I GET /Hello/example
then HelloWorldHandler2.GetHelloWorld
is called with parameter Hello
when I would expect it to be called with example
.
Workaround 1
If I reverse the order of the configuration:
ResourceSpace.Has.ResourcesOfType<Resource2>()
.AtUri("/Hello/{test}")
.HandledBy<HelloWorldHandler2>();
ResourceSpace.Has.ResourcesOfType<Resource1>()
.AtUri("/{test}/{test2}")
.HandledBy<HelloWorldHandler1>();
Then the behavior is as expected:
GET /first/example => HelloWorldHandler1.GetHelloWorld["first","example"]
GET /Hello/example => HelloWorldHandler2.GetHelloWorld["example"]
Workaround 2
If you change the name of parameter:
ResourceSpace.Has.ResourcesOfType<Resource2>()
.AtUri("/Hello/{somethingelse}")
.HandledBy<HelloWorldHandler2>();
public class HelloWorldHandler2
{
public string GetHelloWorld(string somethingelse)
{
return "Hello.World!";
}
}
Then the behavior is also as expected.
Question
- Is it wrong to try to configure URIs in this way? Where they are potentially ambiguous as to which handler should be called?
- Is this a bug in OpenRasta?