In OpenRasta, is it incorrect to configure potentially ambiguous URIs?

Using OpenRasta and using the following two 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 it HelloWorldHandler1.GetHelloWorldis called with parameters firstand example, as expected.

If I get /Hello/example, then it HelloWorldHandler2.GetHelloWorldis called with a parameter Hellowhen I expect it to be called with example.

Workaround 1

If I changed the configuration order:

ResourceSpace.Has.ResourcesOfType<Resource2>()
    .AtUri("/Hello/{test}")
    .HandledBy<HelloWorldHandler2>();

ResourceSpace.Has.ResourcesOfType<Resource1>()
    .AtUri("/{test}/{test2}")
    .HandledBy<HelloWorldHandler1>();

Then the behavior will be as expected:

GET /first/example => HelloWorldHandler1.GetHelloWorld["first","example"]
GET /Hello/example => HelloWorldHandler2.GetHelloWorld["example"]

Workaround 2

If you change the parameter name:

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 expected.

Question

  • Is it wrong to try to configure the URI this way? Where are they potentially ambiguous as to which handler should be called?
  • Is this a bug in OpenRasta?
+3
1
  • , , , 2. , .

/Hello/example /{test}/{test2}, , , .

URI, :)

+2

All Articles