locked
CRM 2011 - Plugins Development - (Best Practices on Visual Studio Project Development) RRS feed

  • Question

  • Hello Gurus/Experts/MVPs,

    You all have been working on Plugins and related Visual studio projects for years, since i am starting for the first time, so need to know the best practices on how do we manage the projects. I know its an incremental learning process but still to have an idea ahead of time is always beneficial.

     

    Scenario

    • For the project i am working on, i will have close 20 new entities
    • Most likely i will end up writing plugin code for 15 entities minimum (including the base and custom)
    • There will be scenario(s) where i have two or more plugins (one for Update other for Create) for a same entity (please correct if i am guessing it wrong)

    Question

    • How shall i structure my projects in Visual Studio
    • Shall i create 15 different projects for example (one for entity Account, one for entity Contact, one for Contact Address) + with same namespace

     

    HOPEFULLY YOU HAVE GOT MY POINT? How do i structure that kind of plugins development in Visual Studio. Sorry i apologize in advance i am new to Visual Studio so please guide me right direction.

    Would really appreciate if you can suggest something on this?

     

    Look forward to hear from you.

    Kind Regards,

     

     

    Wednesday, July 20, 2011 6:22 PM

Answers

  • My two cents:

    If you are going to release this as a single "package" I would have a single project.  I typically have separate classes for Insert/Update because the event parameters tend to be different and you have to handle the situation accordingly.

    Definitely look into automating the deployment via the command-line, import xml or possible the file-based deployment in Dev which allows you to swap out the DLL in the CRM /bin directory (it did in 4.0 anyway).  Registering 15-20 plugins by hand would be a bore!

    • Marked as answer by itsgonabeme Monday, July 25, 2011 6:09 PM
    Wednesday, July 20, 2011 8:27 PM
  • I always stick to a same project. you can have different classes for different entities.

    I will create one physical file for an entity and add different event handler classes to same file.

    Here is a sample, I create a file AccountCallout.cs and add different event handler classes to it.

     public class AccountCallout {

            protected string getInstanceID(DynamicEntity DE) {

                return ((Key)DE.Properties["accountid"]).Value.ToString();

            }

        }

     

        #region  PreCreate

        public class AccountPreCreateHandler : AccountCallout, IPlugin {

            void IPlugin.Execute(IPluginExecutionContext context) {

         }

     

       #region  PostCreate

        public class AccountPostCreateHandler : AccountCallout, IPlugin {

            void IPlugin.Execute(IPluginExecutionContext context) {

         }

     

    If your create and update are doing the same thing you can create just one class for that something like PostCreateUpdateAccountHandler and register 2 steps.. one for create and second one on update event.

     

    I hope this helps


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Marked as answer by itsgonabeme Monday, July 25, 2011 6:10 PM
    Thursday, July 21, 2011 12:13 AM

All replies

  • Also is this advisable to have two classes that will perform two operations (Create/Update) for a single entity lets say Contact.

    In otherwords:

    • I will have two classes 1) ContactInsert 2) ContactUpdate, 
    • Will use OneAssembly whatever the projectname in plugin Registraton
    • So now when i will register the plugin i can have both the plugins available and i can bind them with order of sequence

    Make sense? or I can do both Insert/Update in the same execute function.

    What do you say?

    Wednesday, July 20, 2011 8:08 PM
  • My two cents:

    If you are going to release this as a single "package" I would have a single project.  I typically have separate classes for Insert/Update because the event parameters tend to be different and you have to handle the situation accordingly.

    Definitely look into automating the deployment via the command-line, import xml or possible the file-based deployment in Dev which allows you to swap out the DLL in the CRM /bin directory (it did in 4.0 anyway).  Registering 15-20 plugins by hand would be a bore!

    • Marked as answer by itsgonabeme Monday, July 25, 2011 6:09 PM
    Wednesday, July 20, 2011 8:27 PM
  • Hey snydMan thank you so much for your advise, appreciated.

    I kind of understood what you said in the last part "Definitely look into automating the deployment via the command-line, import xml or possible the file-based deployment in Dev which allows you to swap out the DLL in the CRM /bin directory (it did in 4.0 anyway).  Registering 15-20 plugins by hand would be a bore!"

    But i don't how to get it done?

    Wednesday, July 20, 2011 8:30 PM
  • I always stick to a same project. you can have different classes for different entities.

    I will create one physical file for an entity and add different event handler classes to same file.

    Here is a sample, I create a file AccountCallout.cs and add different event handler classes to it.

     public class AccountCallout {

            protected string getInstanceID(DynamicEntity DE) {

                return ((Key)DE.Properties["accountid"]).Value.ToString();

            }

        }

     

        #region  PreCreate

        public class AccountPreCreateHandler : AccountCallout, IPlugin {

            void IPlugin.Execute(IPluginExecutionContext context) {

         }

     

       #region  PostCreate

        public class AccountPostCreateHandler : AccountCallout, IPlugin {

            void IPlugin.Execute(IPluginExecutionContext context) {

         }

     

    If your create and update are doing the same thing you can create just one class for that something like PostCreateUpdateAccountHandler and register 2 steps.. one for create and second one on update event.

     

    I hope this helps


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Marked as answer by itsgonabeme Monday, July 25, 2011 6:10 PM
    Thursday, July 21, 2011 12:13 AM