简体   繁体   中英

Asp Web Api Breeze in layered application

I currently have an ASP Web API project and the goal is to create a SPA.

I'm using EF Code first and have the following solution structure:

- BookClub.Entities
- BookClub.DataAccess (DbContext, generic Repository, ...)
- BookClub.BusinessLogic (UOW, Facade pattern)
- BookClub.Web (ASP Web Api (v2))

I would like to give Breeze a try but I don't really know what would fit where. All the examples use a Context or Repository in the ApiController. This should be avoided and per entity a BusinessLogic layer Facade should be used. But how would my Controller look like then?

Has anyone ever done this before?

Your controller just facilitates the conversion of your business logic entities for the views you define. If you have build up a business layer then simply use it in the controllers get/put methods. The code below would return a Book in json format.

[HttpGet]
[ValidateAntiForgeryToken]
[OutputCache(NoStore = true, Duration = 0)]
public ActionResult GetBook(int bookID)
{
    BookBL bookBL=new BookBL();
    Book model=bookBL.SelectOne(bookID);
    return Json(model, JsonRequestBehavior.AllowGet);
}

//Return a partial view instead 
[HttpGet]
[ValidateAntiForgeryToken]
[OutputCache(NoStore = true, Duration = 0)]
public ActionResult GetBookView(int bookID)
{
    BookBL bookBL=new BookBL();
    Book model=bookBL.SelectOne(bookID);
    return PartialView("Partials/BookView", model);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM