ABP.IO: Get all items of ReadOnlyAppService without PagedAndSortedResultRequestDto

697 views Asked by At

I would like to use the power of ReadOnlyAppService to expose a simple object (NetworkDevice) to my Angular front-end. So I wrote a simple app service:

public class NetworkDeviceAppService: ReadOnlyAppService<NetworkDevice, NetworkDeviceDto, Guid>, INetworkDeviceAppService
{
    public NetworkDeviceAppService(IReadOnlyRepository<NetworkDevice, Guid> repository) : base(repository)
    {
    }
}

In the Angular client, I am forced to send a PagedAndSortedResultRequestDto to get the NetworkDevices:

private getNetworkDevices() {
  let request = new PagedAndSortedResultRequestDto();
  this.networkDeviceService
    .getList(request)
    .subscribe(res => {
      this.networkDevices = res.items;
    })
}

but I don't want to specify a MaxCount because I want all objects, without paging.

How can I implement it in a clean way.

Unclean solution I though about:

  • Send 2'000'000 as maxResultCount
  • Add a method public async Task<IListResult<NetworkDeviceDto>> GetAllAsync() in my NetworkDeviceAppService
  • Request data in loop in client

Is there an equivalent to ReadOnlyAppService without PagedAndSortedResultRequestDto?

1

There are 1 answers

4
Evram Ehab On

The best option is to override the GetListAync method that is used for the get all, here is the virtual method itself:

GetListAsync default implementation

Now, you can send in an empty argument of type IPagedResultRequest in place of the generic TGetListInput, this way, if you decide to implement paging later, you can just fill it, otherwise, you can just ignore implementing the paging part, essential just copying the the whole method without the line that does paging. BTW this is the standard way to implement your own custom methods in abp, is to find the default being used, override, copy and then modify the implementation to your liking.

P.S: The method in the attached picture is found here: Volo.Abp.Application.Services.AbstractKeyReadOnlyAppService.GetListAsync