Our blog contains the activity stream of Orchard Dojo: general news, new resources or tutorials are announced here.

Featured tags

IIS
API
SMS
SEO
All tags >

Advanced Orchard: accessing other tenants' services

Many using Orchard's multi-tenancy feature sooner or later want to share data between tenants or generally, execute some operations on other tenants from one tenant. This is possible! Let's see how. First some core Orchard fundamentals: Orchard creates so called shells for tenants. These shells describe that sub-application what a tenant is, among others the shell also has its own Autofac IoC container. This container deals with all the dependencies that are injected or otherwise requested. The interesting thing is that you can access the shell - the shell context - of all running tenants and through it also their IoC container. Now if you have the container you can make dependency resolution calls on it - what means that you can resolve services from that shell, i.e. that tenant. public class TenantAccessDemo { // ShellSettingsManager lets you access the shell settings of all the tenants. private readonly IShellSettingsManager _shellSettingsManager; // OrchardHost is the very core Orchard service running the environment. private readonly IOrchardHost _orchardHost; public TenantAccessDemo(IShellSettingsManager shellSettingsManager, IOrchardHost orchardHost) { _shellSettingsManager = shellSettingsManager; _orchardHost = orchardHost; } public void UseServicesFromTenant() { // Fetching the shell settings for a tenant. This is more efficient if you have many tenants with the Lombiq Hosting Suite, // see below. var tenantShellSettings = _shellSettingsManager.LoadSettings().Where(settings => settings.Name == "TenantName").Single(); var shellContext = _orchardHost.GetShellContext(tenantShellSettings); // Creating a new work context to run our code. Resolve() needs using Autofac; using (var wc = shellContext.LifetimeScope.Resolve<IWorkContextAccessor>().CreateWorkContextScope()) { // You can resolve services from the tenant that you would normally inject through the constructor. var tenantSiteName = wc.Resolve<ISiteService>().GetSiteSettings().SiteName; // ... } } } If you're operating a multi-tenant environment you may also want to look at the Lombiq Hosting Suite: among others it has a Maintenance feature that you can use to run code in the context of tenants in a safe and scheduled way. Also it has an extended ShellSettingsManager that stores shell settings in the database: this means you can have any number of tenants, you can even fetch their settings by name or you can page when listing them and you don't have to take care about all the Settings.txt files in App_Data.

Beginning with Orchard: what to start with?

So you'd like to begin exploring Orchard because somebody sold Orchard to you. This is great! Now probably your next question is: how should I start, how can I try Orchard in action? Glad you asked. There are several simple and less simple ways, all free, so let's see. We'll start with the easy ways and build up the tension so you end up with the most complicated one if you want to become an Orchard developer. Going on a test drive with "Try Orchard!" No registration, no setup, nothing required, you can just go to Try Orchard!, open one of the continuously re-installed demo sites and play with it. This is the simplest way of taking the first steps with Orchard. Be aware though that Try Orchard! is really just for testing: since the demo sites are wiped out hourly you don't try to publish your blog there! Creating an Orchard site on DotNest DotNest is the Orchard SaaS provider: this means that you can simply register and create Orchard websites that run in the cloud without any hassle. Your website will just work: you don't have to deploy and later upgrade it, you can just use it. With DotNest you can try out Orchard very simply, very quickly and since your website is already hosted for you you can also show it to everybody. Apart from getting used to the user interface and features of Orchard you can also get into the basics of Orchard theme development with it and style and customize your Orchard website in a lot of ways. Convenience does come with disadvantages: due to the architecture of DotNest you can't install custom modules, so you have to use what is already available (that however should be enough for a big part of websites). Creating an Orchard website on Azure Web Sites Still not very complicated but a bit more advanced than using DotNest is going with Azure Websites. On MAWS after a free registration you can create websites from the Azure Gallery where you can select Orchard to deploy in one click too. Your Orchard site on MAWS will be completely under your control: you can install any module and theme you want too. However this also comes with responsibilities: you have to maintain your website yourself, upgrade and fix it as necessary. Installing Orchard locally via WebMatrix The first two options showed you the quickest ways of beginning to use Orchard that don't require you to install anything on your computer. Now we're getting into the realm of running Orchard on your local computer! WebMatrix is a simple development toolbox that you can also use to install and run Orchard on your box, as explained in the Orchard documentation. This gives you even more control but also more work to do: you can do what you want with your local Orchard instance, you can even start writing code for your custom Orchard theme or module and run those too. From WebMatrix it's also relatively easy to deploy your Orchard site to a public host. However with this option you have to maintain your site, fix any issues that third-party modules you install may cause and you have to keep Orchard up-to-date yourself. Running Orchard locally from the full source This is the real hardcore option, but you'll need to do this if you want to be a black-belt Orchard developer. You can download the full Orchard source either as a zip file from under the Releases section of the project site or you can even clone the repository via git from https://github.com/OrchardCMS/Orchard.git. You'll need Visual Studio to open, build and run the source: but since you're an aspiring developer this shouldn't be a big deal. By using the full source you can browse through Orchard's internals to get to know it better. If you need examples you'll have all the built-in modules at hand. Running Orchard locally and deploying it is the same as with any other web application. You can simply run Orchard by hitting (Ctrl +) F5 and it will spin up through IIS Express. If you want to get away from the simple SQL CE database option and want to use a proper database you'll have to install and configure SQL Server too. You can even use the full power of IIS and run Orchard as you would on a naked Windows Server. Getting Orchard running with IIS and SQL Server is something not trivial though. If you're working in a team or you just want to store your code in source control things get a bit even more complicated but there are established practices that you can use. Good luck with getting up and running with Orchard!

Thank you for everybody participating in Dojo Course!

UPDATE (2017-11-22): Dojo Course 2 is released with new, updated videos! Dojo Course is over - for now. We'd like to thank everybody for following the course and giving valuable feedback! Here's a quick recap of what this awesome experiment was about.

Open Dojo Course and university Orchard course

Start Date: 9/18/2013 12:00:00 PM End Date: 12/20/2013 12:00:00 PM After the first-ever Orchard university course we aimed for repeating the course while also massively expanding its audience by giving the tutorials in English. Óbuda University was our host this time too. Students enrolled to the course as usual but this wasn't just an ordinary course: using the same tutorials (from videos captured in classes), extensive supportive materials and notes we also ran an online course in parallel, Dojo Course. The course started with introducing Orchard's user interface and built-in features. Following were topics about theme development and module development, covering the most important pieces of knowledge an Orchard developer should know. For the last tutorial we've taken requests from on-site participants and online viewers. Dojo Course was the first free and open Orchard online course, available to anybody. With about 8000 views until the end of the course we got to train more people on Orchard development than it would be ever possible through a non-online course. The resulting playlist of videos is the most comprehensive Orchard tutorial set to day.

Last lesson: viewers' requests - Dojo Course

UPDATE (2017-11-22): Dojo Course 2 is released with new, updated videos! In the last lesson of the Dojo Course, we look into a few topics asked by you! Let's see Facebook Suite, Antispam and C# scripting! Facebook suite: installation and usage of the several widgets that bring Facebook features into your website! Antispam: Orchard offers a few solutions out of the box to fight spam! They are: JavaScriptAntiSpamPart, ReCaptcha, Akismet and Typepad. C# scripting: how to add C# code on the frontend which can be integrated with other features, e.g. content validation and Workflows! Thank you for your attention in this 3 months and have a very good year filled with awesome Orchard stuff! Remember: if you have any questions don't hesitate to ask them by creating a new issue in the Orchard issue tracker with the "discussion" label. Make sure to prefix your thread's title with "Dojo Course - "! We keep an eye on these issues. Also follow us on Twitter to get notified about the latest Dojo Course news, including when a new tutorial is posted. Do you have some feedback about the course? Please send it in.

Useful and interesting services to enhance your features - Dojo Course

UPDATE (2017-11-22): Dojo Course 2 is released with new, updated videos! Dojo Course is almost over, so we move on to the spicy parts of the Orchard API that enable you to do really interesting things! An in-depth recap on what we did so far in our PersonList feature. Content querying: using Orchard's LINQ-like API, the IContentManager service to retreive content pieces (including usage and optimization points). How to integrate your features into the administration menu? Running code periodically using background tasks. Running code at a specified time using scheduled tasks. Creating system-wide event handlers to be able to communicate with other pieces of logic in an even more loosely tied way. And a little addition to migrations: you can implement an Uninstall method in your Migrations class to add some logic which will run when your feature is being removed from a system (hopefully nobody will use it ;) ). Stay tuned for the (really) last part of the Dojo Course before Christmas! Remember: if you have any questions don't hesitate to ask them by creating a new issue in the Orchard issue tracker with the "discussion" label. Make sure to prefix your thread's title with "Dojo Course - "! We keep an eye on these issues. Also follow us on Twitter to get notified about the latest Dojo Course news, including when a new tutorial is posted. Do you have some feedback about the course? Please send it in.

Client-side development and a little more of the Orchard API - Dojo Course

UPDATE (2017-11-22): Dojo Course 2 is released with new, updated videos! This week on Dojo Course we move on to some frontend-related development and see how to use static resources and other important features provided by MVC and Orchard. After that we return to the server-side to learn something new. How to add your static resources to your templates? Script/Style.Include/Require. Some userful helpers to customize your templates. Dynamically creating and displaying a shape. How to protect yourself against cross-site request forgery attacks? Posting forms and using the MVC model binder to check if the entered data in our editor is valid or not. Some debugging and bug hunting (restarting the system solved the mystery). And now, for something completely different: file management in Orchard using the IStorageProvider. Remember: if you have any questions don't hesitate to ask them by creating a new issue in the Orchard issue tracker with the "discussion" label. Make sure to prefix your thread's title with "Dojo Course - "! We keep an eye on these issues. Also follow us on Twitter to get notified about the latest Dojo Course news, including when a new tutorial is posted. Do you have some feedback about the course? Please send it in.

End of Dojo Course nearing! What do you want to learn a bit more about?

UPDATE (2017-11-22): Dojo Course 2 is released with new, updated videos! The last two tutorials of Dojo Course will soon come - they are already recorded. This brings us to the project works! There are many of you who enrolled to Dojo Course: it's almost time for you to submit the project work if you'd like to get a certificate of accomplishment! To help you (and so you can also watch the last tutorials of course) we've extended the deadline of the submissions: you now have time until 20th December to submit your work. Remember that you can still request us to review your code as explained in the FAQ. Remember: we can only grade your project and thus issue you a certificate of accomplishment if you submit your work! Also, don't forget about the short presentational video! And now something else: on the last lesson we'll mostly hear the students of the university course present their work; however, we'll have some spare time, about half an hour. If you'd like to learn about something that we haven't covered in the course or would like to see an explanation more in-depth about a topic now it's time for you to chime in: submit your idea in a comment here! We'll evaluate the proposals and pick what is the best for that half an hour (maybe a bit more), then we'll publish this very last tutorial later. Time is short: please submit your ideas in the next 24 hours, at least until Wednesday noon, CET!

Diving into the Orchard API - Dojo Course

UPDATE (2017-11-22): Dojo Course 2 is released with new, updated videos! This week on Dojo Course we dive into the Orchard API, use some of the build-in services and extending the capabilities of our module to make it even better! Using LazyField<T> to load data lazily so they are only loaded when we really need them. Using Work<T> to load dependencies lazily so they are only resolved when we really need them. Applying the [Admin] attribute for admin-related Getting to know an other Orchard service: IAuthorizer. Creating our own permissions by implementing the IPermissionProvider. Using the ContentManager so we can finally work with content items! Generating ad-hoc shapes and matching them to an actual template. Implementing the IResourceManifestProvider interface for managing static resources. Remember: if you have any questions don't hesitate to ask them by creating a new issue in the Orchard issue tracker with the "discussion" label. Make sure to prefix your thread's title with "Dojo Course - "! We keep an eye on these issues. Also follow us on Twitter to get notified about the latest Dojo Course news, including when a new tutorial is posted. Do you have some feedback about the course? Please send it in. Haven't you enrolled yet? Why not do it some time in the near future like right now?

Content Part development continued - Dojo Course

UPDATE (2017-11-22): Dojo Course 2 is released with new, updated videos! This week on Dojo Course we are giving life to our content part by adding several Orchard-y code pieces to it, though the result is far from being Frankenstein-like. While doing that, we also discover some interesting and useful pieces of the Orchard API. Creating a migration for our Contents feature. Difference between ContentPartRecord and ContentPartVersionRecord: versioning content parts. Making your content part attachable to content types (on the Admin UI). Creating a content type using migrations and attaching parts to it. Creating a handler for our content part to do some plumbing (e.g. StorageFilter). Creating a driver for our content part to cover server-side part of the the user interface interaction. How displaying a shape works, what is DisplayType? Shape templates (also editors) and using Placement. Using InfosetPart to store a part's data in the content item's XML infoset document. This eliminates content part record lazy loading, providing a significant performance gain. The importance of driver shape factories. How to make your content part support importing and exporting? Remember: if you have any questions don't hesitate to ask them by creating a new issue in the Orchard issue tracker with the "discussion" label. Make sure to prefix your thread's title with "Dojo Course - "! We keep an eye on these issues. Also follow us on Twitter to get notified about the latest Dojo Course news, including when a new tutorial is posted. Do you have some feedback about the course? Please send it in. Haven't you enrolled yet? Why not do it some time in the near future like right now?