#1 2023-03-31 00:44:27

htits2008
Member
Registered: 2015-03-25
Posts: 31

two DB service have same method,how to

使用接口建立服务,我设计了一个TInterfacedObjectWithCustomCreate为基类的ImplementationClass。现在,我有两个不同root的DB,aDB,bDB.分别注册了这个ImplementationClass。在ImplementationClass的方法里,我怎么分别这是运行在aDB或者是bDB?或者说,我在方法的运行期间,怎么样获取它注册的工厂类和TRESTSERVERDB


Using an interface to create a service, I designed an ImplementationClass with TInterfacedObjectWithCustomCreate as the base class. Now, I have two different root DBs, aDB and bDB. Each has registered this ImplementationClass. In the ImplementationClass method, how can I distinguish whether this is running on aDB or bDB? In other words, how do I obtain the registered factory class and TRESTSERVERDB of a method during its operation

Last edited by htits2008 (2023-03-31 01:44:06)

Offline

#2 2023-03-31 02:54:55

htits2008
Member
Registered: 2015-03-25
Posts: 31

Re: two DB service have same method,how to

I define a function named fDB; And It done.

function FDB: TRestServer;
begin
 fDB:=ServiceRunningContext^.Request.Server;
end;   

Last edited by htits2008 (2023-03-31 02:56:27)

Offline

#3 2023-03-31 06:52:05

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

Re: two DB service have same method,how to

It works, but I may inject the information in the class itself implementing the service, if possible.

Offline

#4 2023-03-31 07:34:04

htits2008
Member
Registered: 2015-03-25
Posts: 31

Re: two DB service have same method,how to

When I called an interface service in a long running thread on the server, an error occurred. Some objects are not initialized

Offline

#5 2023-03-31 08:02:46

htits2008
Member
Registered: 2015-03-25
Posts: 31

Re: two DB service have same method,how to

ServiceRunningContext^.Factory.ORM; can do some CRUD

Offline

Board footer

Powered by FluxBB