Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload