Why do we use Namespaces in Business Central Extensions?

Those that have been creating Business Central extensions before release 23 didn’t have access to such a concept. Why do we need them all of a sudden?

The challenge with a system like Business Central is that it is built on the concept of Extensions extending Extensions. There is an enormous number of extensions available, and it is growing every day. With all these customizations out there, it is hard to enforce rules around name uniqueness. Additionally, namespaces allow us to group customizations together into logical groups.

When you are creating an extension, providing a unique namespace for your extension keeps all your items and names from conflicting with another extension installed in the system.

There is an added performance benefit to namespaces. By telling the system explicitly where to look for objects through the “using” declaration, the compiler knows exactly where each object should be, and it reduces the amount of reflection the system has to perform to find the right object.

Currently we are using both a Prefix/Suffix system in conjunction with namespaces. At the time of writing this, we are in a transition period where namespaces are available and best practice, but the prefix/suffix system is still required as we transition.

The biggest question I get is “How do I know what name space to use?”

Let’s say we want to extend the Customer table (table 18). In Visual Studio Code we go to the .alpackages folder and click on the Microsoft_Base Application app file.

We find and double click on the Customer table, which opens the source code for the Customer table. Right at the top of the table is the namespace.

From here you can also see all the other namespaces that the page uses, which in the case of the Customer page is 60 additional name spaces. The number of available namespaces can be bewildering; however Visual Studio code does a great job of hinting us to what namespaces we need to use.

That is currently the state of the AL namespace. I expect it to become more important as the AL language grows and advances over the years.

Leave a comment

Trending