You are not logged in.
Pages: 1
Hi AB,
We're sitting with a situation where we'd like out DTO's to implement certain interfaces. I realize that we should not inherited from TSynPersistent, in these cases, but where do you suggest we inherit from then?
Offline
DTOs are value objects.
They are transmitted by representation.
So interfaces variable are not suitable for such parameters.
But if you use interface parameters as callbacks, you can execute the interface implementation on the server side from the fake client interface generated by mORMot's SOA.
See http://synopse.info/files/html/Synopse% … l#TITL_149
Offline
Hi AB,
Sure - but we have a function to populate a drop down, for instance. It would be great to pass the array of DTO's directly to it and by using an interface it could extract the correct description to use.
Offline
You may use an interface-base callback here.
But it would be IMHO over-complicated in such cases.
Just return the DTOs, e.g. the TStringList as expected by the UI, then let the client code update the UI with the returned values.
Otherwise, you may start to couple your service with the UI too much...
Offline
Let me explain it like this:
type
IDescribable = interface
function getID : integer;
function getDescription : RawUTF8;
end;
TPerson = class(TSynPersistent, IDescribable)
private
fID : integer;
LastName: RawUTF8;
FirstName: RawUTF8;
protected
function getID : integer;
function getDescription : RawUTF8;
published
property ID : integer read fID write fID;
property FirstName : RawUTF8 read fFirstName write fFirstName;
property LastName : RawUTF8 read fLastName write fLastName;
end;
Then on my client side I can have a library function:
procedure populateList( aStrings : TStrings; aData : array of IDescribable )
var I : integer;
begin
for I := low( aData ) to high(aData) do begin
aStrings.AddObject( aData[i].getDescription, aData[i] );
end;
end;
and call it like this:
var
UserNames : TPersonDynArray;
begin
SomeServiceINterface.GetLookupValues( aSomeLookups );
populateList( cbUserDropDown.Items, aSomeLookups );
..
Please note - this is just from the top of my head to trying and explain what I'm trying to do.
Offline
An array of IDescribable won't work.
But a single IDescribable (if defined as IInvokable with a GUID) could be passed from the client side to the server side.
Honestly, I do not see any benefit of such a pattern.
Just define a getList method returning a TStringList, which would be applied on the client side to whatever "array of IDescribable" interfaces you expect.
It would avoid a lot of back/forth communication between the server and the client, and make your SOA system much more stable.
Offline
Pages: 1