This project is read-only.

Question about the product

Topics: Core
Apr 9, 2013 at 12:56 AM
I have a need to build out a web site from 100's of files. I evaluated your product and super excited to learn about it, but for now, I need to read these files and create 100's of pages programmatically. How would I go about doing this? I traced things to the DefaultContentManager which I am assuming is the class I need to instantiate but I couldn't figure out how it where it was configured for AutoFac. Any suggestions on how to begin?

Apr 9, 2013 at 12:19 PM
You correctly discovered that you have to use ContentManager, just not its concrete implementation directly. Such services in Orchard are always used through constructor-based dependency injection, by using their interfaces (here you would inject IConentManager). For samples how to use this service see the Training Demo module, particularly ContentsController.
Apr 9, 2013 at 4:24 PM
Awsome.. thanks Piedone!

Apr 10, 2013 at 10:24 PM
Okay, I followed your instructions, which are very helpful. I also understand about the dependency injection via specifying the interfaces as parameter types. I guess what I'm asking is, where do the dependencies in question get registered with the AutoFac container?

My understanding (which is light, forgive me) is that you can register dependencies via an AutoFac custom created module (refered to by Web.config), or you can liste them directly in an AutoFac Web.config section. I was unable to trace this down and my thought process was to create a console app, register everything needed to connect to the right repositories, and then do my dump by calling the controller.

Hope I'm not asking too many novice questions. My apologies.
Apr 10, 2013 at 10:36 PM
Dependency registration happens somewhere deep inside Orchard and you don't have to think about it. There's the IDependency marker interface: if an interface derives from it, then a class implements it then you'll be able to get an instance just by adding the interface reference to your ctor (see the Docs). You don't have to deal with registration, Orchard does it for you.

BTW if you start to go through the Training Demo from the start (StartHere.txt) it will guide you through these basic concepts too.
Apr 11, 2013 at 5:25 AM
Okay.. I think I understand. So based on what you are saying, I'm assuming that the classes with the IDependency interface are, by default, the ones loaded by AutoFac and since the unit tests explicitly register them, it overrides the default behavior. Is that correct?

I'm not sure if I was clear enough but I will not be creating my pages through the Orchard Web app directly. It will be done with my own application.. initially a console app that burns through hundreds of files to create pages and the menu structure.
Apr 11, 2013 at 10:55 AM
Yes, one addition: unit tests use explicit registration because automatic dependency injection doesn't work in unit tests (and this has a reason: for tests you should always set up the environment first).

That's why I showed you ContentsController because it creates content items programmatically. You can use the same techniques to create content items from a command that runs in the Orchard command line.
Apr 11, 2013 at 4:53 PM
Thanks Piedone. I think that puts me in the right direction and gives me more knowledge regarding AutoFac as well.
Apr 11, 2013 at 5:11 PM
Great, good luck, have fun :-)!