How to “Pass configuration data to your plug-in” and what's the purpose of the same ? Any real time scenario with example?

一世执手 提交于 2020-01-24 15:03:30

问题


What's the use of passing configuration data to plugin and how to do this ?

https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/write-plug-in

Pass configuration data to your plug-in When you register a plug-in you have the ability to pass configuration data to it. Configuration data allows you to define how a specific instance of a registered plug-in should behave. This information is passed as string data to parameters in the constructor of your class. There are two parameters: unsecure and secure. Use the first unsecure parameter for data that you don't mind if people can see. Use the second secure parameter for sensitive data.

The following code shows the three possible signatures for a plug-in class named SamplePlugin.

public SamplePlugin()  
public SamplePlugin(string unsecure)  
public SamplePlugin(string unsecure, string secure)

回答1:


What's the use of passing configuration data to plugin and how to do this ?

Sometimes we may need to do configuration items just like connection strings or log settings in application development files, web.config or app.config. Similarly, You can pass this from the plugin step when you are registering using plugin registration tool.

The biggest difference that you’ll seen mentioned between these two settings is that the secure configuration is only viewable by CRM Administrators while the unsecure configuration is viewable by any CRM user. However, there’s another important difference: the unsecure config will automatically move between environments with your CRM solutions. This means that even a setting that you might consider fine to let any CRM user read like the URL of a website or settings to enable more verbose trace logging in a development environment might be more appropriate in the secure configuration if you want it to be different between environments. Otherwise, you have to worry about overriding the unsecure config setting in production with the value you have in your development environment every time you import a solution containing the plugin step.

Any real time scenario with example?

  1. Web service credentials (secure)
  2. Website URL that differs between environments (secure)
  3. Log settings that you don’t want to move with a CRM solution (secure)
  4. Template string that you’d want to move with a CRM solution (unsecure)
  5. Constants that you’d want to move with a solution like “MaxRetries” or “NumberOfDaysToFollowUp” (unsecure)

Reference




回答2:


Adding to Arun's answer. The data that is passed in, is set view the PluginRegistrationTool. You can download it from NuGet, but I think it's even easier to download it from Xrm.Tools as a zip and access it form there.

I also suggest defining only a single constructor with default null values:

public SamplePlugin(string unsecure = null, string secure = null) {}

And if you want to go crazy, check out my Visual Studio Accelerator plugin for the XrmToolBox to add the correct SDK references, and optionally some example plugins with unit tests in less than 2 minutes.



来源:https://stackoverflow.com/questions/56393626/how-to-pass-configuration-data-to-your-plug-in-and-whats-the-purpose-of-the-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!