You are not logged in.
Pages: 1
Hi all,
I'm new-be to mORMot. My Question is it possible to have a service inside dll ?
My code in server will be something like :
var
sc : IMyContainer;
loder : IBluginLoader;
begin
......................
aServer := TSQLRestServerDB.Create(aModel,ChangeFileExt(paramstr(0),'.db'),true);
// aServer.ServiceDefine(TClientFactory,[IClientFactory],sicShared);
loder := TBluginLoader.Create('MyDll.dll', 'CreateModuleObject'); //Load dll
sc := IMyContainer(loder.GetBluginInterface()); // Run function "CreateModuleObject" and get result
sc.RegisterFactory(aServer);
.......................
end;
My code in dll will be something like :
{ TMyContainer }
function TMyContainer.RegisterFactory(const aServer: TSQLRestServerDB): boolean;
begin
aServer.ServiceDefine(TClientFactory,[IClientFactory],sicShared);
end;
initialization
TInterfaceFactory.RegisterInterfaces([TypeInfo(IClientFactory)]);
thanks
Last edited by Ehab (2018-05-28 00:39:21)
Offline
If the dll has the very same interface definition, it should work (but not tested here).
Anyway, if you could rather not use a dll, it would be safer, since you may be sure that everything is properly in synch, especially as type definitions (RTTI).
And putting such logic within a dll sounds like a weird architecture choice to me.
Offline
Thanks ab for your quick response. I tried it but it failed, I think due to RTTI may be.
I introduced a mapping unit to load the dll and call the function inside it
if my dll contains the following interface
IdllItnf = interface()
procedure DllProcA();
procedure DllProcB();
end;
then my server unit will contains the following code
IServiceItnf = interface(IInvokable)
['{CF3A7E2C-8189-43F7-AE34-35920D743ED3}']
procedure SrvcProcA();
procedure SrvcProcB();
end;
TMyService = class(TInterfacedObject, IServiceItnf)
private
FDllIntf : IdllItnf;
public
procedure SrvcProcA();
procedure SrvcProcB();
end;
...............
procedure TMyService.SrvcProcA();
begin
FDllIntf.DllProcA();
end;
Now I will use the introduced classes and interfaces as regular
Offline
And putting such logic within a dll sounds like a weird architecture choice to me.
This is an old project divided into some modules each of them in dll and I want to reuse them with minimum effort.
Offline
You need the very same interface definition, with the very same methods and parameters, and the very same GUID (which seems to be missing in the dll).
Otherwise, the RTTI won't match, and the SOA features of the framework will be lost...
Offline
Thanks again ab not only for your response but also for sharing this great project.
My conclusion is to use any dll as service in mORMot is to make a unit contains interfaces that map interfaces inside dll. So no deal with RTTI inside dll.
Even if dll dose not have interfaces and only export functions I still have to make interfaces to map functions inside dll. So I can use the dll as it is.
Offline
Pages: 1