Code-First - SingletonClassFactory

Hi

Using Delphi 12.1 - RODA 10.0.0.1585

I want to create a code-first singleton service.

type
  [ROService(SvcEvents, SvcEventsID)]
  [RONamespace(PanNamespace)]
  [ROSynchronizedSingletonClassFactory]
  TServiceEvents = class(TRORemoteDataModule, IServiceEvents)
    erEvents: TROInMemoryEventRepository;
    procedure erEventsAfterAddSession(Sender: TROEventRepository;
      const SessionID: TGUID);
    procedure erEventsBeforeAddSession(Sender: TROEventRepository;
      const SessionID: TGUID);
  private
  public
  end;

and of course the initialization.

initialization
  RegisterCodeFirstService(TServiceEvents);

How do I know when this service is created?
Second, how do I call a method in this service from another service?

Regards,
Filip

Hi,

this service will be created automatically by demand.

you can create/destroy instance of this service with

function LocalServiceAccess_Acquire(aGuid: TGuid; aName: string): IROService;
procedure LocalServiceAccess_Release(aGuid: TGuid; aName: string; var aService: IROService);

in your case it can be like

  l_myservice := LocalServiceAccess_Acquire(aGuid, aName) as IServiceEvents;
  l_myservice.mymethod;
...
  l_service := l_myservice as IROService;
  LocalServiceAccess_Release(aGuid, aName, l_service);