Single Instance codeunits are essentially an implementation of the Singleton Design Pattern. In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to one "single" instance.
Every object that refers to a codeunit unit of this type will receive the same instance.
I recently had the need to ask myself how can a global variable be accessed in business central through AL Extension Development?
I had found Single Instance Codeunit as the natural first choice. More research material online is needed around this type of codeunit, and I couldn't really get the needed answers to my questions. So I decided to do a quick experiment to figure it out.
To solidify my choice, I experimented with two separate Business Central Sessions as per below -
I created one Single Instance Codeunit, and One Counter Manager Page that Increments/Decrements a Counter variable in the Single Instance Codeunit. I launched two instances of the web client and noted my findings.
On the left, You will see the value of Counter as 3. We can exit the page, carry on with our business and when we come back to the page, we will still see the value as 3. Even if we keep incrementing the global counter in the second session.
I was able to deduce from this that Single Instance Codeunits aren't server side, but exist in the application scope, and the lifetime of the instance is limited to the current client. This was good enough for my purposes.
Find below the code -
Code here:
More details here:
https://docs.microsoft.com/en-us/dynamics-nav/singleinstance-property
http://partnersource.ru/cside.en/html/0456b0e3-873e-427b-8ef5-b9bb0ac7ba6e.htm