D365 Extensibility Attributes
In D365 compared to Ax2012 we have Extension concept for customizing our developments compared to Over layering we are used to in Ax2012.
So, it is important to know how we can control event handlers and Extensions for our custom developments
To control the Extensibility of our Custom code we have three attributes
- Hookable
- Wrappable
- Replaceable
Hookable:
As we know we cannot create event handlers on methods that are Protected or private
So, using Hookable attribute in our code helps to control the event handlers (Pre or Post) and Extensions for our methods
Example:
By using Hookable(true) attribute you can expose even Protected and private methods to event handlers (without Hookable attribute event handlers can be implemented only on public methods).
Similarly, u can disable event handlers for your methods by using Hookable(false) attribute
Note: by using Hookable(false) attribute it overrides CoC(Chain of command) as well and those methods cannot have extensions
Example:
Extension class
Replaceable:
If a method is replaceable, extenders can wrap it by using CoC, but they don't have to unconditionally call next. Although extenders can break the CoC, the expectation is that they will only conditionally break it. The compiler doesn't enforce calls to next.
Example:
Assume Core has implemented a custom logic for checking invoice prices
some other country wants to use custom logic by extending Core then there is no way to skip Core logic (without calling next) in D365.
Previously we could just comment Core code using over layering and implement our Custom region-specific code which is not possible now.
In those cases, we can use Replaceable(true) attribute.
By conditionally calling next we can completely skip core logic and run only region-specific custom logic.
Wrappable:
Wrappable attribute is used to control CoC (Chain of command) implementation for the methods
Wrappable(false) can be used for public and protected methods to prevent Extending the method using CoC.
Note: Private methods cannot have CoC implementation by default, with or without Wrappable attribute
Keep Coding
Original Blog Link : D365 -Extensibility Attributes | Learn and Share (wordpress.com)
Reference:
Attributes that make methods extensible - Finance & Operations | Dynamics 365 | Microsoft Docs
*This post is locked for comments