Fixes issue where multiple instances of ApplicaitonLifecycle are created.

This commit is contained in:
benbierens 2023-05-04 09:16:15 +02:00
parent 5a4a5795b2
commit ab07ac0389
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
1 changed files with 6 additions and 2 deletions

View File

@ -4,6 +4,7 @@ namespace KubernetesWorkflow
{
public class ApplicationLifecycle
{
private static object instanceLock = new object();
private static ApplicationLifecycle? instance;
private readonly NumberSource servicePortNumberSource = new NumberSource(30001);
private readonly NumberSource namespaceNumberSource = new NumberSource(0);
@ -17,11 +18,14 @@ namespace KubernetesWorkflow
// I know singletons are quite evil. But we need to be sure this object is created only once
// and persists for the entire application lifecycle.
get
{
lock (instanceLock)
{
if (instance == null) instance = new ApplicationLifecycle();
return instance;
}
}
}
public NumberSource GetServiceNumberSource()
{