Event publisher methods should not be public (AC0024)
Event publisher methods are intended solely to raise events within the extension that defines them. When declared as public, they can be called by external dependency apps, which is a design smell and breaks the intended event-driven pattern. Additionally, public event publishers are treated as part of the public API, meaning their parameter signature cannot be extended in the future without introducing breaking changes.
Declaring event publishers as local or internal ensures they can only be raised within the defining extension while still allowing external extensions to subscribe to the events.
A code fix is available for this diagnostic.
Example
The following event publisher is public:
codeunit 50100 MyCodeunit
{
[IntegrationEvent(false, false)]
procedure OnBeforeSomething() // Event publisher method 'OnBeforeSomething' should be declared as local or internal. Public event publishers can be called by external dependency apps and prevent future parameter extensions without introducing breaking changes. [AC0024]
begin
end;
}
To fix this, declare the event publisher as local or internal:
codeunit 50100 MyCodeunit
{
[IntegrationEvent(false, false)]
local procedure OnBeforeSomething()
begin
end;
}