Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

.net - How to change Orchard record repository

I work on a project where we're considering using Orchard CMS.

However, we want to use web services as data sources for some of the content items. I guess we have to change the repository implementation in order to make this possible, but I'm not sure about that.

So my question is: Is my guess correct, or is it more complex? And how can it be done then?

Thanks!

Update: I see that Orchard's IRepository interface requires LINQ provider to be implemented. That's impossible in this scenario since the web services are offered via SOAP.

I'll better further describe the scenario:

The website we wish to build has to use web services to get information about an organization members and units. We would like to display members of some organizational unit, for example, on the website. We also want to create our own content type "Event" that should have an M:N relationship (Attendees) with "Member" (from WS).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...