Migrate INotifier to support async implementations, Lombiq Hosting - Tenants - This week in Orchard (28/09/2021)

Gábor Domonkos's avatar
Multi-tenancy, Content model, This week in Orchard, Content part

Migrate INotifier to support async implementations, messaging when getting Part InvalidCastException, Lombiq Hosting - Tenants demo, and many more coming this week! Do you want to know more? Then don't forget to check out our current post!

Orchard Core updates

Migrate INotifier to support async implementations

This new feature is about replacing the INotifier on the front end with a SignalR version, which works asynchronously. INotifier has been updated to use ValueTask when adding notifications. Prefer not to do a custom implementation, as using INotifier allows the front end to also receive messaging notifications from code in the Orchard Core codebase, which is very convenient for us. If you check out the INotifier interface, you will notice that the Add method is now marked as obsolete, and the new one that you can use from now is the AddAsync one.

The new AddAsync method of the INotifier interface

And of course the Information, Warning, Error, Success extension methods are also marked as obsolete and have their async methods, which are used across the whole solution of Orchard Core.

Using the new async notifier extension methods

Messaging when getting Part InvalidCastException

Sometimes if you forget to register your part, you might have some cast errors, and you don't know why. This addition is just about displaying an error message saying you are trying to cast to this part, but please do a double check to make sure you registered this part.

Error message when casting to a custom content part

So, don't forget: every time you create a new content part from your module, you have to register it in the ConfigureServices method of your Startup class by using the AddContentPart extension method. You can find several examples about how to do that like, here you can find the registration of the FlowPart and the BagPart.

Using the AddContentPart extension method to register your Content Part

DisplayText value of a cloned item is set before calling CreateAsync

When cloning a content item, two audit log events are recorded:

  1. An initial create event for the newly cloned item.
  2. A subsequent save event updating the new item with the cloned content data.

The create event in the audit log does not show the DisplayText of the original item but instead repeats the content type. The save event in the audit log displays correctly.

Steps to reproduce the behavior:

  1. Set up a Blog site.
  2. Ensure the Audit Trail feature is enabled and configured to log all content items.
  3. Go to the Manage Content page and clone the About article.
  4. View the Audit Trail and see that the Create event states that Version 1 of the Article Article was created.

The audit log for the created event should state that Version 1 of Article About was created. The fix was pretty straightforward for this one. As you can see here, the solution was to set the DisplayText of the cloned content item before calling the CreateAsync method of the DefaultContentManager, because the CreateAsync invokes the event handlers used by the Audit Trail module.

Fixing setting the DisplayText of the content item when cloning

Demos

Lombiq Hosting - Tenants

The Lombiq Hosting - Tenants repository contains various features that help you build a multi-tenant web application in Orchard Core. With the help of the Tenants Management module, you can set restrictions on tenant creation, while using the Tenants Admin Login module you can log in from the Default tenant's admin dashboard to any other tenants as an administrator user.

In this demo, we will go with the quicker way and use our Open-Source Orchard Core Extensions full Orchard Core solution that contains both of these modules. If you clone that repository and set up your site using any setup recipe, let's just navigate to the admin UI of Orchard Core, and under Configuration -> Features, enable the Lombiq Hosting - Tenants Admin Login module that adds the ability to log in as a tenant's admin user. Make sure that you have also enabled the Tenants module to be able to test the tenant management. :)

Now create a new tenant and enable the Lombiq Hosting - Tenants Admin Login - Sub-tenant feature there that adds the ability to log in to the tenant from the Default tenant. That will mean that admin users from the Default tenant can log in to this tenant as an admin user.

In our example, we have created a tenant called Blog, and if you Edit that tenant, you will see a new Login as an admin user button, which can be used to login to this tenant as an admin user.

Ability to log in to a tenant as an admin user

Now let's see what you can do by using the other module of the Lombiq Hosting - Tenants repository, called Lombiq Hosting - Tenants Management which manages restrictions on tenant creation. The Readme.md file of the Tenants Management module shows how you can specify a list of hostnames that cannot be used to create a tenant. You can write the list of forbidden hostnames as a JSON array in the appsettings.json as follows.

Configure forbidden host names

Now let's go back to the Tenants page of the admin UI and try to create a tenant with a forbidden hostname like forbidden.hostname1.net. If you hit Create, you will get a validation error: forbidden.hostname1.net is a forbidden hostname. And of course, changing the hostname of an already running tenant to a forbidden one will also cause a validation error.

Cannot create a tenant with a forbidden hostname

And as always, if you would like to see more, don't forget to check out this recording on YouTube!

News from the community

A new website using Orchard Core: ICAgile

ICAgile envision a world in which organizations enable and inspire everyone in them to create a better future for those around them. Check out this brand new Orchard Core site here!

New Orchard Core website: ICAgile

If you are interested in more websites using Orchard and Orchard Core, don't forget to visit Show Orchard. Show Orchard is a website for showing representative Orchard CMS (and now Orchard Core) websites all around the internet. It was started by Ryan Drew Burnett, but since he doesn't work with Orchard anymore, as announced earlier it is now maintained by our team at Lombiq Technologies.

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 226 subscribers! We have started this newsletter to inform the community around Orchard with the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here!

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

No Comments

Add a Comment