I current am using ASP.NET MVC and a single Controller for an "API" of sorts. I am using a Service/Repository pattern called from each action method.
Similar to below:
Repository:
public IQueryable<Order> GetOrders()
{
return from sqlOrder in DB.Orders
select new Order
{
Id = sqlOrder.Id,
Name = sqlOrder.Name,
Price = sqlOrder.Price
};
}
Service:
public List<Order> GetOrders()
{
return Repo.GetOrders().ToList();
}
Controller/Action:
public JsonResult GetOrders()
{
var orders = Service.GetOrders();
return Json(orders, JsonRequestBehavior.AllowGet);
}
Everything is working great, however I'm considering moving over to WEB API and Async/Await
Similar to below:
Repository: (no change)
public IQueryable<Order> GetOrders()
{
return from sqlOrder in DB.Orders
select new Venue
{
Id = sqlOrder.Id,
Name = sqlOrder.Name,
Price = sqlOrder.Price
};
}
Service:
public async Task<List<Order>> GetOrders()
{
return await Repo.GetOrders().ToListAsync();
}
Controller/Action:
[ResponseType(typeof(List<Order>))]
public async Task<IHttpActionResult> GetOrders()
{
var orders = await Service.GetOrders();
return Ok(orders);
}
First, are there any problems with this async/await and Repository pattern?
Are there any major downsides to using the raw MVC framework as an "API" of endpoints? Instead of using "Web API"?