Avoid Public Event publisher - #144
Conversation
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
The core distinction between raising and subscribing is correct, but the detection rule is currently broader than the anti-pattern.
A public event publisher can be deliberate when external callers are intended to raise it—an event-bus/facade API, for example. Detection: ... no local or internal modifier would teach agents to flag every such contract even though Best Practice says to use the narrowest modifier that still permits the intended raisers.
Please scope the finding to publishers made public solely for subscriber access, or cases where repository/API context shows no external raising contract is intended. Explicitly preserve intentionally public raisable events as a valid exception. The incidental sample cleanups and the local/internal subscriber-access explanation otherwise look sound.
The detection rule flagged every public event publisher, including ones deliberately public so a sibling app can raise them - a contract `internal` cannot express across app boundaries. Scope the finding to publishers that are public although only their own app raises them, and record the cross-app case as a valid Best Practice option. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0b67b90d-e4b4-4b92-9684-726c72c43b3f
Jesper Schulz-Wedde (JesperSchulz)
left a comment
There was a problem hiding this comment.
Pushed the scoping change to the branch myself rather than sending it back — it was a one-line concern.
Detection now reads: a public publisher although every raiser is in its own app, with an explicit carve-out for a publisher deliberately made public so another app can raise it, and an instruction to treat the modifier as intentional when context does not settle it. Best Practice also gained a third bullet for that cross-app hub case, so the two sections no longer disagree.
The rest of the PR stands as written — the raise-vs-subscribe distinction is right, and the four sample cleanups are all publishers raised only inside their own codeunit. Good addition, thanks.
82422f9
into
microsoft:main
Review agents repeatedly recommend making an event publisher
publicso dependent extensions can subscribe, but the access modifier governs who may raise the event, not who may subscribe — only the object needs to be public, and a public publisher becomes a caller contract that cannot be narrowed after release.Adds a community knowledge article for that choice (
localwhen only the declaring object raises it,internalbehind a public facade) plus samples, and drops the incidentalpublicfrom four existing Microsoft-layer publishers that are raised only from their own codeunit.