You are not logged in.
Hi,
I'm trying to access an interfaced based service method. It is working fine when called from the client, but when calling from the server, ServiceContext.Factory is always nil:
aContext := @mORMot.ServiceContext;
if Assigned(aContext.Factory) then // <---- Factory is nil when called from the server
...
I'm using this as I need to access the Rest server from that method, to do a DB.BackupBackground.
How can this be handled ? Should I not rely on ServiceContext and use a global instance of my server instead ? This won't be great as this method is shared by both client and server.
Any help would be greatly appreciated.
Offline
Yes, there is no factory involved from the server side, by definition.
To access the current TSQLRestServer instance (and e.g. its ORM/CRUD methods), use aContext.Request.Server and not aContext.Factory.Server.
Request.Server is the safe access point to the underlying TSQLRestServer.
See http://synopse.info/fossil/info/66c5abe847
Offline
aContext.Request is nil too in that case
Offline
OK then, I will do that
Thanks!
Offline
I received the following PM from "douglasmmm" regarding this thread. Unfortunately, I do not recall how this was fixed and do not have access to that test anymore. So I'm posting the message here in case somebody can help him:
about you post "@mORMot.ServiceContext.Factory is nil when method is called from Serve" in Synopse forum.
you could implement the solution?
I ask because I could not understand when AB says 'is to inject the TSQLRestServer instance in the interface constructor".grateful
Offline
Offline