0

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?

Damien R
  • 65
  • 9

1 Answers1

1

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

Evram Ehab
  • 106
  • 4
  • I am not really fond of copy-pasting the code to modify one line. If the base method change, I'll have to change my code. – Damien R Sep 13 '22 at 11:17
  • Maybe I could override `ApplyPaging` to just `return query`. It could misslead the caller of `GetListAsync` because he passed a parameter to tell what he wants but I don't know if I can have better – Damien R Sep 13 '22 at 11:18
  • 1
    I see why you might not like this approach, if the base changes, you might want to change your own implementation. Maybe you can create a class that inherits this one, register the service, and override the method and use it instead? This way at least you have one place that you would change your implementation in. I do this in my own solutions and been working with abp for years, they are good developers that will -most of the time- create good logs of changes, stating breaking changes if any. They have decent documentation if you look enough. – Evram Ehab Sep 14 '22 at 13:45
  • Thanks you for your answer and sharing your experience. Apparently, the "perfect" solution I was hoping is not possible directly in abp. I will inspire from your advices and acquire experience on abp to have a better feeling about this kind of things. – Damien R Sep 16 '22 at 06:22