Extending Setup

Topics: Writing modules
Oct 6, 2011 at 4:22 PM


I am looking to extend the creation of a new site and tenant to fit this scenario:

A potential customer hits our default site then selects to register a new site.  A form allows them to enter basic site info (site name, site alias for subdomain, site user owner, passwords, potential credit card)  for tenancy.  After submitting, the data is used to create a new site tenant through ITenantService and the site is "Setup" (features enabled, database modified to include new schema).  The customer is redirected to their setup site.

Alternately, instead of doing database modification, feature creation from the default site, I can redirect to the customer to their new tenant site and provide a custom set of setup screens (similar to the current model).  This would allow me to have more granular control over the display, recipe selection, extra processing steps, etc.

I've attempted to do this is a number of ways: 

  1. From my default site registration controller, call back to ISetupService.  This fails for a number of reasons.  The first appears to be the Orchard.Setup module is no longer loaded after the default site is setup and Autofac cannot resolve the concrete type SetupService.  The second issue is that ISetupService works in the context of the current shell, types such as ShellSettings and IDataMigrationIterpreter are all framed to setup the site with current shell settings.
  2. Looked at plugging in a custom Setup module.  It looks lke ShellContextFactory CreateSetupContext is creating a ShellContext with hardcoded Orchard.Setup.  I wanted to avoid changing anything dealing with the core of Orchard.

Any suggestion or simple solutions on how to accomplish this would be appreciated.  This might well be a case of me missing the obvious.  

Thank you


Oct 6, 2011 at 6:28 PM

Hi Mike,

We have similar needs on our current project.  We ended up modifying Orchard.Multitenancy and Orchard.Setup to meet our needs.  We're not using a self serve model just yet, so we modified Orchard.Multitenancy to automate the vast majority of tenant setup for us (connection information, generate a new database, etc.).  We currently still use the Multitenancy control panel to then provision the site.

We modified Orchard.Setup with a custom recipe and views so that once provisioned, the end user just needs to enter the site name and click setup to access their new site.

We are intending to move in a self serve direction, but there are still some issues with the base platform that we need to overcome.  Prior to 1.3, all other tenants froze during the provisioning and setup of a new tenant.  Sebastien has made immense strides in making multitenancy more robust, and I haven't had a chance yet to see if Sebastien's changes in 1.3 solve this issue (it's the main reason we're still provisioning by hand off hours).

To get to self serve nirvana, I'm thinking we're going to mash up the functionality of adding a site in Orchard.Multitenancy with the site setup features in Orchard.Setup.  That's still a couple months away for us though (hopefully by the end of the year).


Oct 7, 2011 at 5:08 PM

Hi Steve,

I ended up following a similar path after reading your reply, rolling a module for the tenant creation that includes my custom connection, alias, etc and then modifying the existing Orchard.Setup module.  The tenant module is client facing, so I'll have to keep a close eye on the tenant freezing issue you mentioned.  I'm not expecting high volume initially.  It would be great to get to a full self serve model if it make sense from a performance standpoint.

I'd be interested in hearing about any progress you make in the future.

Thank you for the information!


Aug 28, 2012 at 2:26 PM

Hi Guys,

On the latest version you can impersonate the tenant using it's shell settings then resolve the ISetupService reference, like so:

    var tenant = _tenantService.GetTenants().Where(i => i.Name == tenantName).FirstOrDefault();
            if (tenant == null)

            using (var environment = _orchardHost.CreateStandaloneEnvironment(tenant))
                ISetupService setupService = environment.Resolve<ISetupService>();
                using (new TransactionScope(TransactionScopeOption.Suppress))
                    setupService.Setup(new SetupContext
                        AdminPassword = "adminadmin",
                        AdminUsername = "admin",
                        SiteName = " Preview",

I had to supress the transactions for it to work, hope it helps you.



Aug 29, 2012 at 5:12 PM

This code would be a really nice idea for a sitecreator module. Enable module -> have form in frontend and let users create a site through the wizard.

Are you creating such a module and planning it to release it as a module on the gallery? That would be really fantastic to show off the power of Orchard.