Wanna make plugin / Custom Workflow more developer friendly ?
It's very hard to find CRM implementation without custom plugin /Action / Workflow. Even though the way how we implement / develop a code base has been leveraged with NuGet extensions , there are however few nice to have features which can save time and make the developer's task more effective and faster ,cutting down a dedicated document just to handle runtime exceptions/error that raise just because of the entity's prop changes .
The entire developer fraternity is always use to these terms "Early Bound" and "Late Bound". Here we can explore the Early bound approach embedding it in plug-in development which can actually be a life save in a project where there is a dynamically changing properties with more plugins or custom code rather .
So before we start implementing the Early bound , let's try to understand what it actually means from here.
There are may NuGet extensions for creating early bound classes/ Entity . Here we can have a look at Delegate.XrmContext .It is very similar to that of CrmSvcUtil, but has several new features that help you code better and more reliably, and generates files that takes up less space.
Below are the list of features of XrmContext.
- Much smaller code files
- Both entity- and solution-based filtering available
- Option sets are generated as enums
- Attributes of type OptionSetValue (and others) have been abstracted away, and strongly-typed, to allow for cleaner and more robust code.
- Additional helper methods for both entities and the service context have been added.
- Simple deprecation of attributes/fields
- DebuggerDisplay attributes on entities
Let's see how we can achieve this .
- First of all , create a class library (.Net library) , preferably 4.6.2 .
- In the reference ,right click and select Manage NuGet package
- In the package manger , search for "Delegate.XrmContext" as in the image below.
- Once the installation is complete , we would be able to see a list of dlls ,exe and config files as below.
Note : There will be a folder with name XrmContext under which , these files will be placed once the extension's installation is done .
- Among the list of files , we need to config XrmContext.exe.config with the instance uri , user id and password .
- Now is the time to generate the early bound classes by just executing the XrmContext.exe .
- Once the execution is done we can find a new .cs can be found with all the entities in the target instance .
From here this cs file could be reference in our plugin project and use the prop with intellisense support. if there is any change in entity properties , then we can run XrmContext.exe once again and get the changes in early bound classes .