Orchard Core Framework:ASP.NET Core Modular, multi-tenant framework

Source: Internet
Author: User

Orchard Core Framework:ASP.NET Core Modular, multi-tenant framework

The previous authoring Orchard Core builds an ASP. NET core CMS, introducing the ASP. NET core CMS, orchard ASP, with an ASP. NET Core framework.

Support for modularity and multi-tenancy. The entire orchard Core is made up of modules module

First create an empty ASP. NET Core Web application as a base. The following module to learn the establishment and use.

Modular

First, in the previously created ASP. NET Core Web application, create a new class library (. NET core) project as Moduleweb.

Then add MICROSOFT.ASPNETCORE.MVC and OrchardCore.Module.Targets references.

The command is as follows:

Install-package MICROSOFT.ASPNETCORE.MVC

Install-package Orchardcore.module.targets-pre

Then we can add a view folder and Controllers folder, as well as add a homecontroller and corresponding views page.

Because there are no good new shortcuts on the class library, we recommend that you copy them from the ASP. NET Core Web project.

    public class Homecontroller:controller    {        public iactionresult Index ()        {            return View ();        }    }

Home/index.cshtml

The Module is created and then referenced in the ASP. NET Core Web project.

You first need to add a OrchardCore.Application.Mvc.Targets package to your Web project

Install-package Orchardcore.application.mvc.targets-pre

The Moduleweb project is then referenced.

Change Startup.cs as follows:

    public class Startup    {public        void configureservices (iservicecollection services)        {            Services. Addmodules ();        }        public void Configure (iapplicationbuilder app, ihostingenvironment env)        {            if (env. Isdevelopment ())            {                app. Usedeveloperexceptionpage ();            }            App. Usemodules ();        }    }   

Note the references in the project are Microsoft.aspnetcore and Microsoft.ApplicationInsights.AspNetCore, which are configured as follows

  <ItemGroup>    <packagereference include= "Microsoft.ApplicationInsights.AspNetCore" version= "2.0.0"/ >    <packagereference include= "Microsoft.aspnetcore" version= "2.0.0"/>    <packagereference Include= "OrchardCore.Application.Mvc.Targets" version= "1.0.0-beta1-3667"/>  </ItemGroup>  < itemgroup>    <projectreference include= ". \moduleweb\moduleweb.csproj "/>  </ItemGroup>

Then run the program, enter Moduleweb/home/index as follows

Moduleweb is normally available.

Multi-tenancy

Multi-tenant, can directly according to the configuration read user settings, implementation of multi-domain or multiple directories.

First, add a moduleinfo and add a reference:

Install-package Orchardcore.module.targets-pre

Install-package Orchardcore.environment.shell.abstractions-pre

Then add a Startup.cs, implemented as follows:

     Public classStartup:startupbase {//This method gets called by the runtime.        Use this method to add services to the container. //For more information on how to configure your application, visithttps://go.microsoft.com/fwlink/?LinkID=398940         Public Override voidconfigureservices (iservicecollection services) {}//This method gets called by the runtime. Use this method to configure the HTTP request pipeline.         Public Override voidConfigure (Iapplicationbuilder app, Iroutebuilder routes, IServiceProvider serviceprovider) {app. Map ("/hello", branch =Branch. Run (Context= = Context. Response.writeasync ("Hello World from Moduleinfo Linezero"))            ); App. Map ("/info", branch ={Branch. Run (Context=                {                    varShellsettings = context. Requestservices.getrequiredservice<shellsettings>(); returnContext. Response.writeasync ($"Request from tenant: {shellsettings.name}");            });        }); }    }

Access/info reads the shellsetting to get the user's configuration.

Add a Tenants.json in the ASP. NET Core Web application as follows:

{  "Web": {    " State":"Running",    //" requesturlhost": "Web.com",    "Requesturlprefix":"Web",    "Features": ["Moduleweb","Moduleinfo","Orchardcore.mvc" ],    "myconnectionstring":"connectionstring1"  },  "Info": {    " State":"Running",    //" requesturlhost": "Info.com, info.org",    "Requesturlprefix":"Info",    "Features": ["Moduleinfo","Orchardcore.mvc" ],    "myconnectionstring":"connectionstring2"  }}

and change the Startup.cs

         Public void configureservices (iservicecollection services)        {            services. Addmodules (c=c.withtenants ());        }

Then add Moduleinfo to the Web application and run the application.

To access/web/info, the following outputs the web

To access the/info/info, the following will output info

Then there will be two modules under the Web configuration, with only one module in the Info configuration. This information can be used to isolate and differentiate users.

For a deeper understanding of the orchard Core Framework, you can view the source code on GitHub: Https://github.com/OrchardCMS/OrchardCore

Orchard Core Framework:ASP.NET Core Modular, multi-tenant framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.