Govern namespaces and cross-app dependencies

Completed

As a workspace grows to include several related extensions, two objects with the same name in different projects can collide, and a poorly scoped public object can create coupling you didn't intend. Namespaces, dependency declarations, and access modifiers give you the tools to prevent both problems.

Declare namespaces and resolve names with using directives

An AL file declares its namespace at the top of the file, before any object declarations, with the namespace keyword:

namespace Contoso.Shipping.Tracking;

codeunit 71000 "Shipment Status Mgt."
{
    // ...
}

Every object declared in that file belongs to the namespace. The compiler enforces two rules: you can only have one object of a given kind with the same name in a module, and you can only have one object of a given kind with the same name in a namespace. A best practice is to build the namespace name from the developing organization or individual, followed by a product name and a logical grouping, such as Contoso.Shipping.Tracking. Treat the namespace name as stable. Renaming it is a breaking change for any app that depends on your objects, in the same way that renaming an object is.

To reference an object declared in another namespace, use its fully qualified name, or add a using directive after the namespace declaration and before any object declarations:

namespace Contoso.Shipping.Reports;
using Contoso.Shipping.Tracking;

report 71010 "Shipment Status Report"
{
    // Can now reference "Shipment Status Mgt." without the full namespace path
}

Name resolution starts from the closest scope. If a using directive doesn't disambiguate a name that exists in more than one namespace, use the fully qualified name for that specific reference instead of removing the using directive. Learn more in Namespaces in AL.

Diagnose naming conflicts across dependent apps

A naming conflict surfaces as a compiler error when two objects of the same kind and name are visible in the same scope, most often when a project references two dependencies that each declare an object with the same name. Work through the conflict systematically:

  1. Identify both objects and the projects that declare them.
  2. Confirm whether either project already declares a namespace. An object without a namespace declaration is easier to collide with, because it resolves in the global scope.
  3. For unpublished projects, add or correct a namespace declaration in each project so the objects are distinguishable. For published apps, treat adding or renaming a namespace as a breaking change and follow the app's compatibility policy.
  4. Update the referencing project to use a fully qualified name or an unambiguous using directive for each object.
  5. Rebuild the referencing project to confirm the conflict is resolved.

Don't resolve a naming conflict by renaming an object that's already published. A rename breaks every dependent app that uses the object. Adding or renaming a namespace can also break dependent apps because it changes how they address the object. Establish namespaces before publication when possible. For a published app, preserve the existing contract or manage the change as a breaking compatibility update.

Declare dependencies and control access boundaries

A project reference or an app dependency only makes an object reachable; it doesn't determine whether other code should call it directly. Use access modifiers on tables, table fields, codeunits, and queries to define which objects are part of a project's intended public interface:

Access modifier Scope
public Reachable from the declaring module and any module that references it. This is the default when the Access property isn't set.
internal Reachable only from code in the same module, unless the consuming module is explicitly listed in the internalsVisibleTo setting in app.json.
protected Applies to table fields only. Reachable from code in the same table or a table extension of that table.
local Applies to table fields only. Reachable only from code in the table or table extension where the field is defined.

Mark implementation details internal and keep only the objects other projects need to call public. This keeps the API surface small and lets you change the internal implementation later without breaking dependent projects. Access modifiers are enforced at compile time only. They express an intended API boundary, not a runtime security boundary, so don't rely on Access = Internal to protect sensitive data or operations. Learn more in Using access modifiers in AL.

Weigh coupling tradeoffs

Every dependency and every public object is a commitment. A project reference resolves quickly during development, but it also means the referencing project can't compile or publish until the referenced project is available and compatible. Before you add a new cross-app reference, confirm that the capability doesn't already exist in a lower layer, that the object you depend on is intentionally public, and that you're not exposing an internal implementation detail as a side effect of solving an immediate problem. A workspace with clear namespaces, a minimal public surface, and dependencies that only point toward lower or equally scoped layers is easier to extend and upgrade over time.