Using Microsoft's asp.net web api stuff.
What is the best way to structure Visual Studio project(s) for a REST api?
Should I make a new project for each type of object and have them in one solution?
Customer
Address
Bank
Or have them all in the same project with just different classes?
Is there any benefits to either method?
This API is going to at some point encompass every data source I have.
I think that you should have a single Web Project otherwise you will have multiple HTTP endpoints. So I will assume that your question is where to put all the Web API controllers (class derived from ApiController
, see MSDN).
Usually we have all the Web API Controllers in the web project so that they are separated from the other application layers. Controllers are very easy, they just forward the call to a repository or another service.
In one project we have also separated the controllers primary because they can be plugged without recompile the project (sort of addon).
If you use some sort of IoC + Dependency Injection library (that I strongly suggest) then the controllers are created by the container so they can be located in any referenced assembly, you should only register all the controllers inside the container.
Here a tutorial on how to use Castle Windsor with ASP.NET API: Dependency Injection in ASP.NET Web API with Castle Windsor by Mark Seemann.
Here another tutorial for Ninject: Adding Ninject to Web API.
Another suggestion is to use Attribute Routing because I think it is more powerful and easy to use. For more information see this article. Basically each controller/action define its own route, for example:
public class OrdersController : ApiController
{
[Route("customers/{customerId}/orders")]
[HttpGet]
public IEnumerable<Order> FindOrdersByCustomer(int customerId) { ... }
}
Finally just pay attention because the controller name (class name) should be unique across all the solution.