Orchard Core and Service Fabric - Introduction

Introduction

Hello friends! These are exciting times. Not only did Microsoft recently release .NET Standard 2.0, .NET Core 2.0 and ASP.NET Core 2.0, but the Orchard Community has been steadily hacking away at a brand new version of Orchard, called Orchard Core. Orchard Core is built on top of ASP.NET Core, which is a lean and mean re-implementation of ASP.NET that is optmizied for server hosting. What's more, ASP.NET Core can run on any OS that provides an implementation of the .NET Standard. You can therefore run your ASP.NET Core code not only on Windows, but also on Mac and Linux, and more OS to come. In addition, Azure Service Fabric can host ASP.NET Core applications, which means that we can also host Orchard Core applications.

And that's what this blog series series is all about. We will have a look at what Orchard Core is, how we can host it with Service Fabric and call Service Fabric services from a custom module. To demonstrate the various concepts and technologies, we will be building a small application called Books Unlimited, which is a fictive company that wants to display their books to the world via an Orchard Core website, because they think it's an amazing framework, and I agree. They also heard about service oriented architecture and microservices and how powerful that is, so the books will be provided by a microservice hosted within Service Fabric. Great choice!

The series consists of this introduction to Orchard Core and Service Fabric and the following 4 parts:

Part 1 - Setting up the "BooksUnlimited" Service Fabric Project

Part 2 - Adding Orchard Core

Part 3 - Creating the "BooksCatalog" Service Fabric Service

Part 4 - Creating the "BooksCatalog" Orchard Core Module

At the end of the series, we will have a fully functioning Service Fabric solution that hosts two Service Fabric stateless services:

  1. BooksUnlimited.Web, which is a stateless service exposing a Kestrel Communication Listener that delegates HTTP requests to ASP.NET Core using Orchard Core middleware.
  2. BooksUnlimited.BooksCatalog, which is a stateless service exposing a Service Remoting Listener that handles requests from services within the fabric.

Although the sample application might be contrived, it demonstrates a powerful combination of hosting a full-blown CMS in Service Fabric that can then easily consume microservices hosted by Service Fabric. Service Fabric applications can be deployed as a unit, and benefit from everything that Service Fabric has to offer.

Source code

The final solution can be found here.

Orchard Core

So, what is Orchard Core? I could say that it's the next major version of Orchard, but that might not convey the fact that Orchard Core really is a brand new product. It is a complete re-implementation of Orchard 1. Where Orchard 1 is built on top of ASP.NET MVC 4, Orchard Core is built on top of ASP.NET Core.

Does this mean your Orchard 1 applications cannot be upgraded to Orchard Core? I would say that is a pretty accurate statement. If you're interested in upgrading, or more aptly put: migrating, you would be better of starting from a clean slate with Orchard Core, and port over your existing modules and themes manually.

Although Orchard Core is brand new, many of the existing O1 concepts are carried over. Orchard Core still has a Content Types, Content Parts and Modules. But, it also adds new concepts, and the underlying technology is quite different.

Let's have a brief look at some of the main differences between O1 and O2.

Orchard Core is built with ASP.NET Core

Because Orchard Core is built on ASP.NET Core, it inherits many features of that underlying framework. And since ASP.NET Core is different from ASP.NET 4 in so many ways, so is Orchard Core when compared to Orchard 1. Orchard Core embraces much more from its underlying ASP.NET Core framework than Orchard 1 does from ASP.NET 4. This means that Orchard Core's codebase is more lean, where many features don't have to be implemented. In fact, the ASP.NET Core team borrowed many concepts from Orchard 1 when they designed it! Which is perhaps not that surprising when you realize that Sébastien Ros, Orchard's full time developer, is part of the ASP.NET MVC team.

Orchard Core is highly modularized as NuGet Packages

This, in my opinion, is one of the most powerful things about Orchard Core: the fact that it is completely divvied up into NuGet Packages. What this allows you to do, is to create your own new ASP.NET Core project from scratch, and only take those features from Orchard that you're interested in. Orchard Core is no longer a full-blown CMS. It's a vast array of NuGet packages offering reusable components to build an application with. Orchard CMS is a package that depends on many lower-level packages that are reusable. You're interested only in the the ability to devide your ASP.NET Core application up into modules? No problem, just take the OrchardCore.Modules package. Or perhaps you're only interested in the ability to execute recipes? Why not, just take OrchardCore.Recipes. Or what about caching? There's a reusable OrchardCore.DynamicCache for that.

This modular setup fulfills one of Orchard Project's promise of providing "a set of re-usable components that make it easy to build individual .NET-based applications that appeal to end-users, scripters and developers".

This also moves away from the traditional "attitude" towards the Orchard.Web.csproj in O1 where we as application developers didn't really "own" that web project. We got this project automatically when cloning Orchard 1, and we would only modify that project and its contents if absolutely necessary. Most likely, we would make a few changes to web.config, and that would be that. The real deal of our custom applications built with O1 would be done in the form of custom modules and themes. With Orchard Core, we take full ownership of our own ASP.NET Core web project. In fact, we create this project ourselves. Here, we are in charge of creating our own ASP.NET Core project, and then start configuring the middleware pipeline with middleware that we want to use for our app. One such middleware component could be OrchardCms, in addition to many others.

Orchard Core embraces a Document Database data model

Orchard's composable content type model has always been a better fit for a document-based storage model, but for historical reasons, a relational database model was used. Each content part would be stored in its own table, sometimes requiring large joins between content part tables to load a set of content items. This was slightly improved with the introduction of the shift to InfoSet storage, where content parts could now store their data in the same record as the content iten itself, significantly boosting content item load times.

Orchard Core moves away from the relational model, and fully embraces a document model using YesSQL, a .NET document database working on any RDBMS. Notice that YesSQL still relies on an RDBMS such as SQL Server, but that it models entities as documents rather than tables with columns representing an entity's attributes. This model greatly speeds up data retrieval from storage, since content items now contain all of their information in the form of a document, stored as a single record. Even related content items, e.g. a content item owning a list of other content items (think Menus), can be stored in a single document. Very powerful indeed.

Orchard Core is Fast

While I think Orchard 1 was as fast as it could be given its dynamic nature, it had a serious limit in terms of scalability and the number of requests it could handle per second. With output-cache enabled, and depending on hardware and page complexity, O1 was able to handle about 400 requests per second. Using that same hardware, Orchard Core is able to handle 1,200 requests per second without output cache enabled. Enable output cache, and it is able to handle a jaw-dropping 50,000 requests per second. Let me say that again: Fifty. Thousand. Requests. Per. Second.

Service Fabric

Alright then. What is Service Fabric? Taken from their documentation, Service Fabric is:

"a distributed systems platform that makes it easy to package, deploy, and manage scalable and reliable microservices and containers. Service Fabric also addresses the significant challenges in developing and managing cloud native applications. Developers and administrators can avoid complex infrastructure problems and focus on implementing mission-critical, demanding workloads that are scalable, reliable, and manageable. Service Fabric represents the next-generation platform for building and managing these enterprise-class, tier-1, cloud-scale applications running in containers."

In other words, Service Fabric is a very powerful runtime that enables us to deploy and host a collection of services that makes it easy to implement a microservice oriented architecture.

By using Service Fabric, you can:

  • Deploy to Azure or to on-premises datacenters that run Windows or Linux with zero code changes. Write once, and then deploy anywhere to any Service Fabric cluster.
  • Develop scalable applications that are composed of microservices by using the Service Fabric programming models, containers, or any code.
  • Develop highly reliable stateless and stateful microservices. Simplify the design of your application by using stateful microservices.
  • Use the novel Reliable Actors programming model to create cloud objects with self contained code and state.
  • Deploy and orchestrate containers that include Windows containers and Linux containers. Service Fabric is a data aware, stateful, container orchestrator.
  • Deploy applications in seconds, at high density with hundreds or thousands of applications or containers per machine.
  • Deploy different versions of the same application side by side, and upgrade each application independently.
  • Manage the lifecycle of your applications without any downtime, including breaking and nonbreaking upgrades.
  • Scale out or scale in the number of nodes in a cluster. As you scale nodes, your applications automatically scale.
  • Monitor and diagnose the health of your applications and set policies for performing automatic repairs.
  • Watch the resource balancer orchestrate the redistribution of applications across the cluster. Service Fabric recovers from failures and optimizes the distribution of load based on available resources.

The Sample Application

To see both Orchard Core and Service Fabric in action, we'll build a very small application called "Books Unlimited". The application will consist of two "microservices":

  1. An Orchard Core website called "Books Unlimited"
  2. A service called "BooksCatalog"

The goal is to create a custom Orchard Core module that makes a call into the "BooksCatalog" service. The "BooksCatalog" service is a Service Fabric Stateless service that exists on its own as a true microservice, and has the sole purpose of providing all of the books offered by Books Unlimited. The microservice will not expose its operations to the outside world (although it could if we expose the right kind of "listener"). Instead, we will expose a "remoting listener" that we can communicate with from other services within the Service Fabric application. In our case, we will be communicating with the service from a custom Orchard module.

Enough of this. Let's dig in!

Go to Next Part.

1 comment

  • ... Posted by Terry Posted 12/19/2017 05:55 AM

    I've tried working through this a number of times with the latest version of OrchardCore but even though everything builds and the services are deployed.... the custom orchard module doesn't show up in Orchard admin to be enabled.

    All components build, the orchard module is in the modules folder of the web app, there is a project reference to the module from the web app, the deployment to SF seems fine with Orchard working.... it just won't see the module.

    Any ideas what I'm doing wrong here?

Leave a comment