"EventRepository property is not assigned" exception with pre-initialized TROPooledClassFactory

RO SDK .1137
Delphi XE6

When you change a service’s class factory to pooled and set the parameter to preinitialize the pool to true, you get an exception when trying to run the server application, though the service’s EventRepository property is set.

Exception:
‘NewService.EventRepository property is not assigned’

To reproduce, you can create an empty server application from template, e.g. combo service, add in-memory session manager and event repository, set the service’s properties and change the class factory to

fClassFactory := TROPooledClassFactory.Create(‘NewService’, Create_NewService, TNewService_Invoker, 5, pbWait, TRUE);

Thanks,
Bernhard

Thx, it is known issue. in some cases service instance can’t correctly assign properties from datamodule.
usually it appears in console applications.
as a workaround, pls initialize them manually, like

procedure TNewService.RORemoteDataModuleCreate(Sender: TObject);
begin
   EventRepository := OlympiaData.OlympiaEventRepository;
   SessionManager := OlympiaData.OlympiaSessionManager;
end;

Hi Evgeny,

Yes, I think it was me who reported this issue 6 or 7 years ago :wink:

As I mentioned above, it happens in a blank application created from combo server template, not a console application. Explicitly assigning the session manager and event repository worked in the past, but not this time.

Thanks
Bernhard

at moment of creating pooled class factory, server datamodule isn’t created. it is a reason for this problem.
as a workaround, you can create server datamodule before creating polled classfactory:

initialization
  Application.CreateForm(TServerDataModule, ServerDataModule);  /// moved from .dpr

  fClassFactory := TROPooledClassFactory.Create('NewService', {$IFDEF FPC}@{$ENDIF}Create_NewService, TNewService_Invoker,5, pbWait, True);