
Hi,
I am looking for some examples on how to initialize AutoMapper in a Custom Workflow.
Thanks
*This post is locked for comments
I have the same question (0)Automapper's mapper method is stateful and not thread safe, so you should not use it for custom workflows. The CRM SDK specifies that Microsoft CRM caches the custom workflow instances (as well as the plugin instances), so the Execute method should only contain thread safe, stateless components.
If you need to map records in your custom workflow you should add your own mapper functions. If you're copying whole records you could look into MemberWiseClone, which is a shallow copy function inherited from System.Object
https://msdn.microsoft.com/en-us/library/system.object.memberwiseclone%28v=vs.110%29.aspx
More information about thread safe/stateless plugins and custom workflows can be found here:
https://msdn.microsoft.com/en-us/library/gg328515.aspx
"For improved performance, Microsoft Dynamics CRM caches custom workflow activity instances. The custom workflow activity’s Execute method should be written to be stateless because the constructor is not called for every invocation of the custom workflow activity. Also, multiple system threads could execute the custom workflow activity at the same time. All per invocation state information is stored in the context, so it is not recommended to use global variables or member variables to pass data from one invocation to the next"