2013-04-30 27 views
2

自從7個月前我就開始用CRM了。我仍然不知道是什麼,爲什麼使用以及爲什麼這些變量。什麼是插件CRM中的Context,serviceFactory和Service 2011

public void Execute(IServiceProvider serviceProvider) 
{ 

    Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) 
    serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); 

    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory) serviceProvider.GetService(typeof(IOrganizationServiceFactory)); 

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); 
} 

我已經搜索了沒有任何運氣的答案。

感謝

回答

1

MSDN提供了一個很好的一套從Understand the Data Context開始的文章。

總之,這裏有雲:

  1. IPluginExecutionContext是,所有的上下文信息帶到你的代碼。 InputParametersOutputParameters成員包含插件正在被觸發的記錄,前後圖像,處理後的消息()實際數據取決於您如何註冊插件:pre VS post,確切消息,聯機或離線...
  2. IOrganizationService對象允許您查詢組織服務。最常見的使用場景是CRUD操作(創建,檢索,更新,刪除:注意死鎖)。
+0

我明白了。非常感謝! – 2013-04-30 16:06:29

+0

serviceFactory.CreateOrganizationService(context.UserId):如果一個用戶屬於多個組織,該怎麼辦? – Sean 2016-08-09 07:28:24

1

IPluginExectionContext:

  1. 定義傳遞給插件在運行時的上下文信息。包含描述插件在其中執行的運行時環境的信息,與執行管道相關的信息以及實體業務信息。
  2. 執行上下文在運行時在Execute方法的System.IServiceProvider參數中傳遞給插件。您可以從服務提供商獲取上下文,如下面的插件代碼所示。 //從服務提供者獲取執行上下文。

IPluginExecutionContext上下文=(IPluginExecutionContext)serviceProvider.GetService(typeof運算( IPluginExecutionContext));

IOrganizationService接口: 提供元數據和數據組織的編程訪問。