web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Why it is not recommended to put event handlers in an extension class?

(0) ShareShare
ReportReport
Posted on by 115

Hi. I've created an extension class of PriceDiscAdmCheckPost class (decorated by [ExtensionOf]) and I have placed there my custom methods, chain of commands methods and event handlers. However, as I compiled it, the best practice checker shows a warning message that says:

"Adding event handlers in extension classes is not recommended, please use instead a regular X++ class for that purpose."

I'm wondering why. I thought the goal was place every piece of custom code for one object in one extension class as much as possible. Due to this, I had to create another class that is not decorated by [ExtensionOf] just for my event handlers for that particular standard class.

If that's the case then, I'd like to ask how I would name my objects then? For my extension class, I named it "PriceDiscAdmCheckPostClassABC_Extension' where ABC is a custom model initials. But how about for my new regular X++ class that has my event handlers? I'm thinking of "PriceDiscAdmCheckPostClassEventsABC_Extension", but I'm not sure if that's the best way to name it. Please help, I can't find any other sources online regarding this matter.

Thanks.

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    Here is a blog post that explains why you should not do it https://daxmusings.codecrib.com/2018/06/accidental-code-extensions.html

  • iridescence Profile Picture
    115 on at

    Thanks for sharing. I somehow understand what he was trying to tell. Event handlers can be accidentally considered as extended methods by the compiler. I guess that answers my main question.

    But considering all of these, how would I name my new class that has event handlers only in it? Can you suggest best practices for it? Thanks in advance.

  • Verified answer
    Blue Wang Profile Picture
    Microsoft Employee on at

    Hi Harvey,

    Extension of classes are named by adding ABC_Extension suffixes to the original class name.

    For implementing event handlers we should use EventHandler_ABC suffix, accompanying original name:

    Please read this Doc:https://zakharov.com/naming-conventions/application-objects/classes/

    -

    A similar thread: community.dynamics.com/.../adding-event-handlers-in-extension-classes-is-not-recommended-please-use-instead-a-regular-x-class-for-that-purpose

  • iridescence Profile Picture
    115 on at

    Thanks for the answer. Cheers!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 659

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 465 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 304 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans