How to change Orchard record repository

谁说我不能喝 提交于 2019-11-27 08:08:10

You don't have to implement an IRepository in case you don't want to fully direct the part storage to somewhere else. I'm currently using WCF service in one of my Orchard-based projects, so your scenario is similar.

You can do it this way:

  1. Wrap your web service proxy in a class implementing IDependency, so you'd be able to inject it into drivers/handlers/controllers etc. For the ease of unit testing and mocking you should create a separate interface, eg. IMyWebServiceWrapper : IDependency and implement it then.
  2. Create appropriate content parts and records. In the records store only the information necessary to locate and fetch data from WS. In the content parts create all necessary properties - they will be loaded from the WS.
  3. Inject your class from point 1. into appropriate content handlers' constructors
  4. Inside the content handler constructor use something like this:

OnLoaded<MyPart>((ctx, part) => { part.MyProperty = myService.GetMyProperty(part.SomeIdToLookup); });

  • MyPart is your part on the Orchard side.
  • MyProperty is some property on your part which will be loaded from WS.
  • myService is your wrapped WS proxy, passed as a constructor parameter.
  • GetMyProperty is a method in the wrapper which call WS and retrieves the necessary data.

Of course you can use other handler events (like OnInitialized, OnCreated, OnPublished etc). You can read more about content handlers here.

I'd also recommend getting a dev startup module from Codeplex for quick development.

Actually you don't need to use a repository or even a record. Depending on what you are trying to do, triggering the fetching logic from a handler might work.

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