1

PreEntityUpdate と PostEntityAssign の 2 つのプラグインがあります。update PostEntityUpdate 内で assign を実行すると、PostEntityAssign プラグインの実行が呼び出されます。PreEntityUpdate から PostEntityAssign に共有変数を渡すことは可能ですか? やってみましたがだめでした…

4

1 に答える 1

1

プラグインのすべての親コンテキストを調べて、SharedVariables コレクションに必要な共有データを見つけようとする必要があると思います。コードの例を次に示します。

 public new void Execute(IServiceProvider serviceProvider)
    {
        string sharedDataKey = "your key defined here";
        bool found = false;

        IPluginExecutionContext currentContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

        // Find shared data among parent contexts
        IPluginExecutionContext context = currentContext;
        while (context != null)
        {
            if (context.SharedVariables.ContainsKey(sharedDataKey))
            {
                found = true;
                break;
            }

            context = context.ParentContext;
        }

        object sharedData = null;
        if (found)
        {
            // Data was found in parent context
            sharedData = context.SharedVariables[sharedDataKey];
        }
        else
        {
            // Data was NOT found in parent context, thereby we create new one
            sharedData = new object();
            currentContext.SharedVariables[sharedDataKey] = sharedData;
        }

        // Do what you want with 'sharedData'
    }

あなたが説明した状況に私が使用した非常によく似たもの。つまり、関連エンティティを更新する PRE 更新エンティティ プラグインが 1 つあります。これにより、すぐにプラグインの別のインスタンスが呼び出されます。

于 2014-04-25T12:47:12.943 に答える