Converting OData Controller to WebApi Controller

Jan 17, 2015 at 9:39 AM
Edited Jan 17, 2015 at 3:58 PM
I am trying to follow the Northwind example provided as sample. In this the oData controller is used to access the data.

How we can convert these code(s) to a simple web api controller. So I can use something like localhost:5000/api/customer to list all the customers whereelse localhost:5000/api/customer/ALFKI to just list one customer.

What configuration changes I have to make to make this scenario to work. Thank you

PS: My goal is to use the framework with ASP.Net webapi to return the data only. And using John Papa Hot Towel template to access this data with Breezejs. Is this scenario can be achieved with this nice framework in first place? Regards

The best I have come to, for converting to Web Api is as below -

Here I don't know how to enable DI/IoC for Unit of Work etc. Is there a better way. Please advice.....
namespace Northwind.Web.Api
{
  [RoutePrefix("api/CustomerX")]
  public class CustomerXController : ApiController
  {

        private readonly ICustomerService _customerService;
        private readonly IUnitOfWorkAsync _unitOfWorkAsync;

        public CustomerXController(
            IUnitOfWorkAsync unitOfWorkAsync,
            ICustomerService customerService)
        {
            _unitOfWorkAsync = unitOfWorkAsync;
            _customerService = customerService;
        }

    [HttpGet]
    [Queryable]
    public IQueryable<Customer> GetCustomer()
    {
      return _customerService.Queryable();
    }

    [HttpGet]
    [Queryable]
    public SingleResult<Customer> GetCustomer(string id)
    {
      return SingleResult.Create(_customerService.Queryable().Where(t => t.CustomerID == id));
    }
  }
}
Coordinator
Feb 12, 2015 at 6:48 PM
This is an MVC question not really related to the framework itself, as for how to implement a WebApi controller, you would simply do this as your normally would, the framework does influence how you would traditionally create a WebApi controller.
Marked as answer by lelong37 on 2/12/2015 at 11:48 AM