Hi All,
Please find the below the concept of all Hookable vs Wrappable vs Replaceable explained in detail.
Hookable
If a method is hookable, extenders can subscribe to pre-events and post-events.
For public methods, you can opt out by adding [Hookable(false)] to the method.
You can opt in for private and protected methods by adding [Hookable(true)] to the method.
If a method is explicitly marked as [Hookable(false)], then it is not wrappable.
Best practices when you write code
When a method is hookable, the compiler generates extra intermediate language (IL) code to enable the method as an extension point. Although the extra code has performance overhead, this overhead is negligible in most cases. However, for performance-critical methods, consider marking the method as non-hookable.
Wrappable
If a method is wrappable, extenders can wrap it by using Chain of Command (CoC). Extenders must call next, because they aren't allowed to break the CoC.
For protected and public methods, you can opt out by adding [Wrappable(false)] to the method.
You can't opt in for private methods.
Best practices when you write code
CoC resembles inheritance in many ways. Typically, if you want other people to be able to call your method but not change it, you mark the method as final. Consider marking these methods as non-wrappable or non-hookable.
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.
To be replaceable, a method must also be wrappable.
For wrappable methods, you can opt in by adding [Replaceable] to the method.
see more details here: https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/extensibility-attributes
No comments:
Post a Comment