0
votes

I am following an RPC approach in one of my Web APIs and for that purpose i am gonna use attribute routing in my controllers.

I am splitting my Controllers by making them partial:

Folder structure pic

ALL the partial files under JDE folder must have the same RoutePrefix and actions will make the url unique.

namespace Enterprise.Api.Controllers.JDE.Distribution
{
    [RoutePrefix("/api/jde/distribution")]
    public partial class JDEController : ApiController
    {

    }
}

I want every partial file to have its own route prefix and every action to have a route.

If i put RoutePrefix in more than one file i get an error.

2

2 Answers

2
votes

Partial files of a class are still considered as one single class and so you cannot use multiple route prefix attributes...consider creating multiple controller types for your scenario...

1
votes

So what i did is this:

First i add this ONE time to my partial APi controller:

[RoutePrefix("api/jde")]
public partial class JDEController : ApiController
{
    public JDEController()
    {

    }
}

And then i add a Route attribute in my methods to get what i want

public partial class JDEController : ApiController
{

    [Route("orders")]
    public IEnumerable<Order> Get(int customerId) { ... }
}