#1 2023-05-06 09:31:38

larand54
Member
Registered: 2018-12-25
Posts: 96

IList<T> in services

I'm very fond of IList but I'm trapped by the fact that I have to declare it as a constant in the parameter list on a service method.
So there is no way to initialize it. sad

I'm sure that there is a solution to this but at the moment I'm lost.


Delphi-11, WIN10

Offline

#2 2023-05-06 19:19:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: IList<T> in services

We did not validate that IList<T> would work as expected for the services... even as a "const" parameter...
AFAIR the only kind of interface supported is for websockets/async callbacks, not lists...

What does currently work, from your tests?

Offline

#3 2023-05-07 10:36:38

larand54
Member
Registered: 2018-12-25
Posts: 96

Re: IList<T> in services

I solved it by replacing IList with an ordinary dynamic array for the service. It requires some more coding but it works. I kept using IList in the repository though as I can initiate the collection in the service before calling the repository methods.

It seems to require too much effort to be worth solving ?


Delphi-11, WIN10

Offline

#4 2023-05-07 13:33:37

tbo
Member
Registered: 2015-04-20
Posts: 335

Re: IList<T> in services

larand54 wrote:

It seems to require too much effort to be worth solving ?

In the client program I work with Spring4D. Here there is also an IList. For this I have connections for various components. The bridge between the two looks like this:

type
  TOrmArticleList = class(Spring.Collections.Lists.TObjectList<TOrmArticle>);
  TOrmArticleObjArray = array of TOrmArticle;

function ...CreateArticleList(const pmcSectionID: TID): TOrmArticleList;
var
  service: IArticle;
  dataArr: TOrmArticleObjArray;
begin
  if not dmDB.RestServer.Resolve(IArticle, service) then Exit(Nil); //=>

  service.GetAllItems(pmcSectionID, [asActive], dataArr);
  Result := TOrmArticleList.Create(dataArr, True);
end;

mORMot provides an ObjArray that fills the list. With the Spring4D classes I have many functions that I don't have to implement myself. If you only need the IList interface, you can write like this:

Result := TCollections.CreateObjectList<TOrmArticle>(dataArr, True);

With best regards
Thomas

Offline

Board footer

Powered by FluxBB