モジュール間の通信は、いったんそれを取得すると難しくありません。これを達成する方法もいくつかあります。 この回答はあなたの最後のコメントに基づいています.Bertrandが正しい方向にあなたを指していたからです。より洗練された例えば、単純なのEventHandler
モジュールA
サービス/ IMyCustomEventHandler.cs
namespace My.ModuleA.Services
{
// This is the eventHandler you inject wherever you need it. (e.g. Module B)
public interface IMyCustomEventHandler : IEventHandler
{
// IContent should suit you in this case but you could also pass in
// just the contentItem id, or whatever else you need.
void SomethingHappened(IContent content);
}
}
モジュールB
コントローラ/ FancyController.cs
ワークフローの使用0 namespace My.ModuleB.Controllers
{
public class FancyController : Controller
{
private readonly IMyCustomEventHandler handler;
public FancyController(IMyCustomEventHandler handler)
{
this.handler = handler;
}
public ActionResult DoSomething()
{
// ...some computation here
this.handler.SomethingHappened(myContentItem);
}
}
}
モジュールC
ハンドラ/ BoringCustomEventHandler.cs
namespace My.ModuleC.Handlers
{
// This is the most basic eventhandler to implement
public class BoringCustomEventHandler : IMyCustomEventHandler
{
public void SomethingHappened(IContent content)
{
// Do whatever here.
// As you can see we handle an Event here in Module C
// that was dispatched in Module B
// via a service declared in Module A.
}
}
}
/アクティビティ
わかりました、今では面白いです。 Orchard.Workflows、Orchard.Tokensの組み合わせ、カスタムEventHandlerとあなたの想像 は、あらゆる種類のシナリオを処理する非常に強力な方法です。 モジュールはこのレベルでお互いに知っている必要はありません(ここでは一般的な記述です)。
モジュールA
まず、我々は、カスタムワークフローアクティビティを定義する必要があります。
は顔をしていることができます。代わりに私たちのカスタムアクティビティで
活動/ SomethingHappenedActivity.cs
namespace My.ModuleA.Activities
{
public class SomethingHappenedActivity : Event
{
// This is a neat convention for avoiding typos.
public const string EventName = "SomethingHappened";
// As the name says, this Activity will be able to start a workflow when triggered.
// There are a lot of existing Activities, so I encourage you to check them out.
public override bool CanStartWorkflow
{
get { return true; }
}
// ... other stuff here
}
}
我々は最終的にいくつかのワークフローの魔法を行うことができます。 ここでの可能性はほとんど無限です。私はこれらの例は少しあなたを助けることを願っています
namespace My.ModuleA.Handlers
{
// This implementation of our custom event handler will trigger workflow activities for us.
public class WorkflowMyCustomEventHandler : IMyCustomEventHandler
{
private readonly IWorkflowManager workflowManager;
public WorkflowMyCustomEventHandler(IWorkflowManager workflowManager)
{
this.workflowManager = workflowManager;
}
// Should be self-explanatory.
// When we invoke our IMyCustomEventHandler.SomethingHappened() event,
// this implementation will trigger our custom workflow activity.
// Also don't forget that you can do all kinds of magic with *Orchard.Tokens*!
public void SomethingHappened(IContent content)
{
this.workflowManager.TriggerEvent(
SomethingHappenedActivity.EventName,
content.ContentItem,
() => new Dictionary<string,object>
{
{ "Content", content.ContentItem },
{ "OtherStuff", "whatever else you want to provide here" }
}
)
}
}
}
ハンドラ/ WorkflowMyCustomEventHandler.csなど、電子メールを書き、
を他のワークフローをトリガすることができます。 私は頭の上からすべてを書いたので、何かを忘れてしまったかもしれません。 ご質問がありましたら、コメントにご連絡ください。回答を更新したり、オーチャード・ジッタ・チャンネルにお越しください。
あなたがしようとしていることは完全には明確ではありません。シナリオを説明できれば助かります。あなたがしようとしているものを達成するための標準的な方法が既にあり、それがうまくいかなければならないかというあなたの考えからは乖離する可能性が非常に高いでしょう。例えば、オーチャードは標準イベントバスを持っています。あなたはそれについて知っていて、それを使わない理由がありますか? –
私はちょうど私がやろうとしているとおそらく彼はそれをよりよく説明しているstackoverflowでこのポストを見つけた:http://stackoverflow.com/questions/25848958/communication-between-custom-modules-in-orchard- CMS。ですから、イベントバスを使用しているように思えますし、Ieventhandlerを実装することは、他のモジュールを参照するのを避けるためにやっていることを達成する方法です。しかし、残念ながら、このURL:http://www.ideliverable.com/blog/ieventhandlerは、私が主題で見つけることができる唯一のチュートリアルであると思われ、私は概念の周りに私の頭を包んで失敗している... –