mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-08-08 02:16:52 +01:00
Add CMFRT coding standards documentation and examples
- Introduced guidelines for "one codeunit one global function" architecture to enforce single responsibility in AL code. - Added best practices and anti-patterns for adding parameters via overloads to maintain backward compatibility. - Documented the importance of never deleting members in AL and always marking them as obsolete. - Established the requirement for OnBefore and OnAfter integration events for global procedures to enhance extensibility. - Defined naming conventions for CMFRT objects, including prefixes and object ID ranges to avoid conflicts. - Implemented patterns for case statements to ensure all cases are handled, including the necessity of an else clause. - Introduced the interface injection pattern to allow pluggable operations in table-level code. - Recommended using Confirm Management for user confirmations to improve testability. - Established a three-permission set pattern for security to ensure proper access control. - Created a review skill for CMFRT AL standards to automate compliance checks against established guidelines.
This commit is contained in:
parent
4119417ce4
commit
c72c0ad685
35 changed files with 866 additions and 0 deletions
|
|
@ -0,0 +1,15 @@
|
|||
// No integration events — dependent extensions cannot intercept or react
|
||||
// to the operation without using an AL override, which is a breaking pattern.
|
||||
codeunit 2045700 "CMFRT BA Item Price Impl"
|
||||
{
|
||||
procedure CMFRTBAUpdateItemPrice(ItemNo: Code[20]; UnitPrice: Decimal)
|
||||
var
|
||||
Item: Record Item;
|
||||
begin
|
||||
Item.SetLoadFields("Unit Price");
|
||||
if Item.Get(ItemNo) then begin
|
||||
Item.Validate("Unit Price", UnitPrice);
|
||||
Item.Modify();
|
||||
end;
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
codeunit 2045700 "CMFRT BA Item Price Impl"
|
||||
{
|
||||
procedure CMFRTBAUpdateItemPrice(ItemNo: Code[20]; UnitPrice: Decimal)
|
||||
var
|
||||
Item: Record Item;
|
||||
Handled: Boolean;
|
||||
begin
|
||||
OnBeforeCMFRTBAUpdateItemPrice(ItemNo, UnitPrice, Handled);
|
||||
if Handled then
|
||||
exit;
|
||||
|
||||
Item.SetLoadFields("Unit Price");
|
||||
if Item.Get(ItemNo) then begin
|
||||
Item.Validate("Unit Price", UnitPrice);
|
||||
Item.Modify();
|
||||
end;
|
||||
|
||||
OnAfterCMFRTBAUpdateItemPrice(ItemNo, UnitPrice);
|
||||
end;
|
||||
|
||||
[IntegrationEvent(false, false)]
|
||||
local procedure OnBeforeCMFRTBAUpdateItemPrice(ItemNo: Code[20]; UnitPrice: Decimal; var Handled: Boolean)
|
||||
begin
|
||||
end;
|
||||
|
||||
[IntegrationEvent(false, false)]
|
||||
local procedure OnAfterCMFRTBAUpdateItemPrice(ItemNo: Code[20]; UnitPrice: Decimal)
|
||||
begin
|
||||
end;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
bc-version: [all]
|
||||
domain: events
|
||||
keywords: [integration-event, on-before, on-after, extensibility, event-publisher, global-procedure, handled]
|
||||
technologies: [al]
|
||||
countries: [w1]
|
||||
application-area: [all]
|
||||
---
|
||||
|
||||
# CMFRT OnBefore and OnAfter for every global procedure
|
||||
|
||||
## Description
|
||||
|
||||
Every global procedure in a CMFRT extension must be bracketed by a paired `OnBefore<ProcedureName>` and `OnAfter<ProcedureName>` integration event declared in the same object. Both events are `[IntegrationEvent(false, false)]` local procedures. The `OnBefore` event passes the procedure's key input variables and a `var Handled: Boolean` parameter. The entry procedure checks `Handled` on return from `OnBefore` and exits without executing its body if a subscriber has already handled the operation. The `OnAfter` event passes the key output variables so subscribers can react to the completed result.
|
||||
|
||||
## Best Practice
|
||||
|
||||
Declare both events at the time the global procedure is written, not as a later addition. Place the `OnBefore` call at the top of the procedure body before any logic, and the `OnAfter` call at the bottom after the last statement. Follow the naming convention `OnBefore<ProcedureName>` and `OnAfter<ProcedureName>` exactly so event consumers can locate publishers by convention.
|
||||
|
||||
See sample: `cmfrt-onbefore-onafter-all-globals.good.al`.
|
||||
|
||||
## Anti Pattern
|
||||
|
||||
Publishing a global procedure without both `OnBefore` and `OnAfter` integration events, or adding events only after a downstream extension explicitly requests an extension point. A global procedure with no event bracket is a black box: dependent extensions cannot inject logic around it without an AL override, which is a breaking pattern. Adding events later is itself a non-breaking change but causes unnecessary churn and review cycles.
|
||||
|
||||
See sample: `cmfrt-onbefore-onafter-all-globals.bad.al`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue