Base solution for your next web application
Open Closed

WebApi vs auto generated service #1142


User avatar
0
ofirav created

Hi

First of all, I would like to say it's a great framework, a real timesaver! I am trying to build a simple app with Angular & EF The angular part is working properly, including a custom controller built for file uploading - I understand the concept repositories, appservice and domain services and it works properly .

My problem is - when I try to call _productsAppService.GetProducts() from WebApi - it returns the exception: "The operation cannot be completed because the DbContext has been disposed"

Same method called from the angular service - works properly.

The row that fails is for example: List<Product> products = _productsRepository.GetAll().ToList();

what am I missing here? The webapi controller inherits from "AbpApiController", I don't touch the connection or the context myself, only working with IRepository<T> ... is there some special configuration for that case?

Thank you in advance, Ofir


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Short answer - 1: Don't inject app service class, inject and use it's interface. Short answer - 1: Or make your web api action UOW (make action virtual and add [UnitOfWork] attribute).

    A better answer: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocRepositoryGetAll">http://www.aspnetboilerplate.com/Pages/ ... toryGetAll</a>

  • User Avatar
    0
    ofirav created

    Excellent! thank you :)