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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Is there a Plugin Design Convention ?

(0) ShareShare
ReportReport
Posted on by 20

So I have my first plugin working (yeah me). 

I've included both the "Create"  and "Update" logic for an Entity in the same class.

This got me thinking.  How to design a plugin.

Should you only create one plugin per entity and use code in the execute method to determine if the call is a PreValidation or Postvalidation and then test for the message type "Create", "update" etc.

Then branch off to methods\ non plugin classes that cater for each combination of options.

Here you know where the first call will be for every occurrence.

Or,  should you breakdown the plugins for each entity into Post and pre validation and then the message type.  eg.

PersonPreCreate.cs  PersonPreUpdate.cs

is there a best practice ?

The answer , "it depends on the situation" could be true. 

But for large organisations with multiple developer groups, commonality of design would help with learning curves, so would take preference over individual style.

I have the same question (0)
  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    as you wrote: "it depends on the situation"

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    If you would like to know the best practices to be followed when designing the plugin then please have a look at below docs page -

    docs.microsoft.com/.../

    Now coming to your question on number of classes for plugin-

    It depends on the requirement, ideally we should have one plugin class per file and then check appropriate message and stage in your code to execute your business logic. However there are some exceptions where you will have to create multiple class file. For instance on same the stage you want to have multple logic to be executed in an order.

    Execution Order -1 Execute some code on Post Update,

    Execution Order - 2 Execute some code on Post update,

    In this case you will need to create two separate plugin class.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Michel Gueli Profile Picture
    982 on at

    Some Tips:

    -Seperate plugin logic from the actual plugin classes, which implement IPLUGIN. Much easier to test.

    -I have a plugin class for each step I use. Folder for each entity. Example incident Folder. 

    --PreOperationIncidentCreate.cs

    --PostOperationIncidentCreate.cs

    --PreOperationIncidentUpdate.cs

    --PostOperationIncidentClose

    -Update same entity where plugin is running on? Yes --> ? PreOperation, No --> PostOperation

    -Custom Security checks --> PreOperation

  • Michel Gueli Profile Picture
    982 on at

    This is not true. It depends on where you put your logic. My logic is always outside of the plugin classes. That makes it reusable.

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 60 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans