This week in Orchard - 01/11/2019

Gábor Domonkos's avatar
This week in Orchard

We had no meeting since the 18th of December so, now we have a lot of improvements to talk about regarding Orchard Core. Let's see them one by one!

On Orchard Core

Fixing configuration issues

The idea is to fix the configuration issues of Orchard Core.

The first one is about to provide a per-tenant configuration. When you have multiple tenants, you might want them to behave differently in terms of connection strings, Azure Blob Storage connection strings, SMTP settings, whatever that can be set in configuration.

Before this PR, there were no way to define configuration to each tenant. Now we have a way to define configuration per tenant.

The next issue is about to reimplement FileShellSettingsConfigurationProvider. If you are not using the CMS, the default provider for the tenant names is in the tenants.json file. It was using the configuration API to load it, which is not the way it should be done.

The Orchard environmental settings discussion is about when you have different environments (production, test, development) and you want to able to define different settings, even site settings or configuration settings. This PR is fixing it. Here we want to be able to define configuration by environment, like production, test and so on. Also, to define configuration per environment variables. So, when you switch to different environments, they will take that into account.

Finally, the use JSON for site settings is about to use JSON instead of YAML for site settings. This PR also removes the usage of YAML.

How do these works? Let's see that in a demo!


Fixing configuration issues

Set up a site using the Software as a Service recipe, because we will create tenants. Now head to the App_Data folder! Before this every site had a folder and a site settings file inside (Settings.txt). The first thing you will see here is the tenants.json file, that lists all the tenants. 

The content of the tenants.json file could be the following.

This JSON document contains the name of the tenants and its properties. The properties you can have inside this file are State, UrlPrefix, RequestHost and Features.

If you go to the Default folder inside Sites, you will find an appsettings.json file instead of Settings.txt.

The only configuration it has so far is the DatabaseProvider, which in this case is Sqlite.

So, the tenants.json now is common to every Orchard Core instance, the appsettings.json will contain only the things that are specific to a tenant.

Now let's create a new tenant based on a different recipe, for example the Blog. Just create it, do not set up it yet. Then open the tenants.json again.

You can see that here we have the new tenant created.

Now, let's set up this tenant and see the content of the appsettings.json inside the Sites/Blog folder.

Furthermore, you can also have an appsettings.json file under the App_Data folder that will apply configuration properties for all the tenants.

You can also define configuration properties under the OrchardCore.Cms.Web folder as well, but this one will never be updated by the application, because it's not accessible. If you want to define custom settings here for all the modules, you can create a section called OrchardCore and inside that you can add custom settings under the name of the module.

Now open the Startup.cs file of the OrchardCore.Media.Azure module.

You can see that it will resolve an IShellConfiguration. It's a new interface, which is implementing IConfiguration, but only gets the configuration for this tenant. If you need to get the configuration for the app itself, you need to resolve IConfiguration.

In the current example we configure the MediaBlobStorageOptions, using the configuration in the section called OrchardCore.Media.Azure.

If you want to define some custom value for a specific tenant (don't forget that the appsettings.json file in the OrchardCore.Cms.Web folder provides app-level settings) you have two options. First, you can create a new section in this file with the name of the tenant and can repeat the modified settings that you would like to add to the current tenant.

Here you could see, that the configuration for the email module in app-level is different than in the tenant-level.

The other way is to define this in the appsettings.json file of the tenant (under App_Data/Sites/Default) in the same format.

You can also have appsettings.json files per environment. You can create appsettings.production.json and appsettings.staging.json files. We also support environment variables. You can create an environment variable that looks like ORCHARDCORE__STAGING__Orchard.Media.Azure__ConnectionString.

There are some bugs to fix before merge these changes to the dev branch. Until that you can find the code in the sebros/configuration branch.

New Text Field editors

In the following PR Antoine Griffard added new Text Field editors to Orchard Core:

  • Email editor
  • Color editor
  • Tel editor
  • URL editor

We created a new content type, called TextFieldEditorDemo and added four Text Fields to it to show the four different kind of editors.

New admin menu

The new admin menu for Orchard Core now works perfectly on mobile as well.

Response Compression module

By enabling the Response Compression module, it will compress the response from the server using GZIP or BR (if your client supports it) and set the max-age value of the Cache-Control in the header.

The media files will be cached for 7 days in the client. Also cache static files for a year as they are coming from embedded resources and should not vary.

Let's look the response headers when loading the clean-blog.css file. Here you can see the max-age property was set for the Cache-Control, that is important for the performance.

Try Orchard Core

Thanks to Antoine Griffard, the Beta version of Try Orchard Core is available, where you can create an Orchard Core application choosing between the Agency, Blog and Coming Soon recipes.

To set up a new site you have to provide your e-mail address and the name of the site. After that you will receive an email that contains the URL of your tenant, the username and the password of the admin user.

Note that the sites will be reset every Monday at 00:00 GMT.

If you are interested in more news around Orchard, don't forget to check out the recording of this week's Orchard meeting!

No Comments

Add a Comment