Create the module which need access to other module database

Topics: Customizing Orchard, General, Writing modules
Aug 9, 2011 at 9:28 AM

Hi I`m newbie in Orchard. this is my first question.

I want to create a module and my module need to access the database from other module. the things I confused is how to access it.

can someone give me a hint or link tutorial to do this one?

 

Thanks and Regards

Aug 9, 2011 at 11:46 AM
Edited Aug 9, 2011 at 11:46 AM

just use dependency injection in your ctor.

public MyService(IRepository<othermoduletype> myRepository)
        {
            MyRepository= myRepository;
          
        }

Aug 10, 2011 at 3:55 AM

Thank you for quick reply..

Actually I dont have idea how to start create module which could access database from other module. I have read Create Hello World Module but I think it`s not give information enough for me.

I need simple tutorial-how-to create module which access database from other module. maybe you can give me the right link or tutorial so I can learn itself first?

 

Thanks and Regards

Aug 10, 2011 at 4:50 AM
michaeldickson wrote:

just use dependency injection in your ctor.

public MyService(IRepository<othermoduletype> myRepository)
        {
            MyRepository= myRepository;
          
        }

hmm..where I put this one?in Driver?

Aug 10, 2011 at 12:34 PM

You can inject it in the driver, controller, etc.  Where to inject it depends on what you need to do and how you need to access the data on the views, etc.  You may also be better served with a relationship if that makes sense.  I am fairly new to Orchard myself and there is a ton to learn on the framework and it is amazingly flexible.  But it is difficult to get your head around everything because it is so flexible.  I would suggest taking a step back and reading the documentation and watching the videos.  There are things that you can do in Orchard that surprisingly does not require you to write any code and is pretty powerful like lists and custom content types.  You really should start from the very beginning and work your way up to a module.  Also, I downloaded pretty much every module and looked at the source for nearly every module to get an idea on how things work.  To start I would recommend looking at these articles:

http://www.orchardproject.net/docs/How-Orchard-works.ashx

http://www.orchardproject.net/docs/Writing-a-content-part.ashx

http://www.orchardproject.net/docs/Creating-1-n-and-n-n-relations.ashx

http://www.orchardproject.net/docs/Understanding-data-access.ashx

And watch the videos as the demonstrations help to cement the ideas even if they are not directly related to what you are trying to accomplish:

http://www.orchardproject.net/docs/Orchard-TV.ashx

I could probably just link to the entire documentation section on the orchard site, but those links above are directly related to what you are asking.  Other things you are going to need to understand in your module development is parts, fields, templates, and the placement.info file.  Once you get the pattern it is pretty straight forward.