Question

I am looking for the C# equivalent of Spring MVC's url mapping using annotations, i.e in Java I can write:

@Controller
@RequestMapping("/some-friendly-url/")
class MyController
{
    @RequestMapping(value = "/{type}/more-seo-stuff/{color}", method = RequestMethod.GET)
    public List<SomeDTO> get(@PathVariable String type,
                             @PathVariable String color,
                             int perPage) {
        ...
    }

    @RequestMapping(method = RequestMethod.POST)
    public String post(@RequestBody SomeDTO somethingNew) {
        ...
    }
}

It's actually much more powerful than this simple example as anyone familiar the the concept knows.

I've tried to search on how to achieve the same with either ASP.MVC 3 or with MonoRail and both frameworks seem to be based on RoR's convention-over-configuration "//" philosophy and it would be hard to achieve the above with them and require a lot of bespoke routing entries outside the controller class with only a small subset of the functionality available via attributes. Spring.NET does not seem to address this either stating that ASP.MVC's routing functionality is sufficient.

Is there anything out there in the C# world that provides this type of functionality? I was just about to start looking into writing something of my own to address this, but I was hoping not to have to do that.

Edit: Finally found the "AttributeRouting" project which is available on NuGet as well: https://github.com/mccalltd/AttributeRouting/wiki/1.-Getting-Started. Works perfectly. Doesn't support to full range of features that Spring MVC does, but supports most of it.

Also Akos Lukacs pointed to another good library below by ITCloud. However that one unfortunately is not available on NuGet.

Était-ce utile?

La solution 2

I Eventually used https://github.com/mccalltd/AttributeRouting/wiki/1.-Getting-Started. Posting this only now for the sake of keeping the question complete.

Autres conseils

Sure, you can use Spring.NET:

http://www.springframework.net/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top