I'm using Delphi Tokyo, latest version. I'm using Spring4D container and declaring an IEventBus (not using the built in singleton) as a singleton.
In one part of my code I call twice the method to UnRegister the current object.
E.g.
if not Assigned(fEventBus) then Exit; // shouldnt be needed but, hey just in case
If fEventBus.IsRegistered(Self) then
fEventBus.UnRegister(Self);
Calling this twice will cause an exception. The exception happens while attempting to Acquire the critical section via FCS. It seems that the finalization section was already called and the FCS critical section is now nil, causing the issue.
In general Finalization sections mixed with Dependency containers will cause trouble. I will suggest an implementation that completely skips the use of that methodology if the developer is not using the built in singleton.
Thank you for your great work with this, it is extremely useful. It will be great if you wrap it into a component so its easier to share and it can be exposed via Delphinus or GetIt.
UPDATE:
I did a quick test changing the Critical sections with a TMonitor (new versions are faster than TCriticalSections due to use of Spinlocks) and it did the trick. Another option could be to put the critical section inside of the object and only use the global one when creating the GetDefault singleton.
Hi,
I'm using Delphi Tokyo, latest version. I'm using Spring4D container and declaring an IEventBus (not using the built in singleton) as a singleton.
In one part of my code I call twice the method to UnRegister the current object.
E.g.
if not Assigned(fEventBus) then Exit; // shouldnt be needed but, hey just in case
If fEventBus.IsRegistered(Self) then fEventBus.UnRegister(Self);
Calling this twice will cause an exception. The exception happens while attempting to Acquire the critical section via FCS. It seems that the finalization section was already called and the FCS critical section is now nil, causing the issue.
In general Finalization sections mixed with Dependency containers will cause trouble. I will suggest an implementation that completely skips the use of that methodology if the developer is not using the built in singleton.
Thank you for your great work with this, it is extremely useful. It will be great if you wrap it into a component so its easier to share and it can be exposed via Delphinus or GetIt.
UPDATE: I did a quick test changing the Critical sections with a TMonitor (new versions are faster than TCriticalSections due to use of Spinlocks) and it did the trick. Another option could be to put the critical section inside of the object and only use the global one when creating the GetDefault singleton.