bcquality/microsoft/knowledge/events/choose-static-vs-manual-subscribers-deliberately.good.al
Jesper Schulz-Wedde 54ddd8ecc2 Add events knowledge domain and review leaf skill
Add a new `events` knowledge domain covering AL events & subscribers,
wired into the AL review pipeline.

- 3 atomic articles (+ .good.al/.bad.al samples) under
  microsoft/knowledge/events/: the IsHandled override pattern, thin
  OnBefore/OnAfter integration-event publishers, and static vs manual
  subscribers.
- New leaf skill microsoft/skills/review/al-events-review.md sourcing the
  events domain.
- Wired into microsoft/skills/review/al-code-review.md (sub-skills + Source
  + description) and README.md (leaf-skill count + domain list).

AL event syntax verified against Microsoft Learn. Samples are
demonstration-only (not compiled by CI). Additive change; no contract change.

Part of #34.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-25 11:58:58 +02:00

52 lines
1.6 KiB
AL

// Demonstration-only AL. Not compiled by CI; illustrates the article.
codeunit 50228 "Item Post Pub Good Sample"
{
procedure PostItemLine(ItemNo: Code[20]; Qty: Decimal)
begin
// ... post the line ...
OnAfterPostItemLine(ItemNo, Qty);
end;
[IntegrationEvent(false, false)]
local procedure OnAfterPostItemLine(ItemNo: Code[20]; Qty: Decimal)
begin
end;
}
codeunit 50229 "Item Post Audit Good Sample"
{
// Always-on behaviour belongs in a static subscriber (the default).
EventSubscriberInstance = StaticAutomatic;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Post Pub Good Sample", 'OnAfterPostItemLine', '', false, false)]
local procedure LogPostedLine(ItemNo: Code[20]; Qty: Decimal)
begin
// Audit every posted line, unconditionally.
end;
}
codeunit 50230 "Item Post Stub Good Sample"
{
// Scoped/temporary behaviour belongs in a manual subscriber.
EventSubscriberInstance = Manual;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Post Pub Good Sample", 'OnAfterPostItemLine', '', false, false)]
local procedure CaptureForTest(ItemNo: Code[20]; Qty: Decimal)
begin
// Record the call so a single test can assert on it.
end;
}
codeunit 50231 "Item Post Test Good Sample"
{
procedure VerifyPostingRaisesEvent()
var
Publisher: Codeunit "Item Post Pub Good Sample";
Stub: Codeunit "Item Post Stub Good Sample";
begin
// Activate the scoped subscriber only for the duration of the test.
BindSubscription(Stub);
Publisher.PostItemLine('1000', 5);
UnbindSubscription(Stub);
end;
}