This project is read-only.

Access other module data step by step

Topics: Writing modules
Jun 27, 2012 at 8:20 AM
Edited Jun 27, 2012 at 9:42 AM

Hi all! I'm new to Orchard and couldn't find clear answer to my question anywhere.

I need to use Orchard.Blogs module from my module code (my module is supposed to create blog posts).

What should I do to get access to Orchard.Blogs? Please don't write like "Just inject dependency and use it", I came here after 2 hours googling for explanation of this thing:)) I need short walkthrough like
1) Reference Orchard.Blogs.dll
2) add this code to that file
3) ....
4) profit

Thank you very much!

Jun 27, 2012 at 11:03 AM

Did I hear "profit"? $$$

From the looks of it you already understand the basics: you understand that you need a reference to the Orchard.Blogs project (do not add the DLL as a reference though).

So instead of writing each step in detail, try this:

Study the BlogPostAdminController class in the Blogs module itself. You'll see *exactly* how to leverage the required services in order to create a blog post programmatically.

In short, this is what you would need to do:

  1. Create your own class (be it a controller or your own service class)
  2. Create a public constructor, taking in an instance of all the interfaces you need: IBlogService, IBlogPostService and IOrchardServices (this is what they mean when theysay "inject your dependencies". There's an excellent course on this on Pluralsight on DI) and store them in private fields
  3. Use the services stored in the private field just like it's done in BlogPostAdminController: Retrieve a Blog to which you want to add a post, create a new content item of type BlogPost, populate all of the fields (either manuaylly, or using the UpdateEditor method of the ContentManager; this really depends on your specific implementation. I mean, where will you get your blog post input from?). Finally publish your new post using the Publish method.
  4. Done



Jun 28, 2012 at 5:50 AM

Thanks for response, I already done like this.