The Orchard Core framework was designed with modularity in mind : A modular design can be characterized by functional partitioning into discrete scalable and reusable components.
Launch Visual Studio and select "Create a new project".
Select "ASP.NET Core Web Application" and click the "Next" button.
Enter the project name "OrchardCoreModularMVCWebApplication" and select the "Create" button.
Select "Web Application" and press the "Create" button.
As you can see, the "OrchardCoreModularMVCWebApplication" project was created.
Lets add another project. Right click on the solution, select "Add" then "New Project...".
Select "ASP.NET Core Web Application" and click the "Next" button.
Enter the project name "OrchardCoreModularEmptyWebApplication" and press the "Create" button.
Select "Empty" and the press the "Create" button.
As you can see, the "OrchardCoreModularEmptyWebApplication" was created.
Lets add another project. Right click on the solution, select "Add" then "New Project...".
Select "Class Library (.NET Core)" and click the "Next" button.
Enter "OrchardCoreModualLibrary" for the project name and click the "Create" button.
Lets add another project. Right click on the solution, select "Add" then "New Project...".
Select "ASP.NET Core Web Application" and click the "Next" button.
Enter "OrchardCoreModualWebAPI" for the project name and click the "Create" button.
Select "API" and press the "Create" button.
As you can see the projects were created.
Lets add a new item to the solution. Right click on the solution, select "Add" and then "New Item...".
Lets add a "Text File" and select the "Add" button.
Right click on the "TextFile.txt" and select "Rename".
Note: Orchard Core changed the Orchard Preview Feed.
Rename it to "NuGet.config". Add the following text:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
Exit Visual Studio. You can press the "X" (Close) in the upper right corner.
Restart Visual Studio and Select the OrchardCoreModualMFCWebApplication" solution.
Visual Studio reloaded the solution.
Click on the "OrchardCoreModularLibrary" modify the project to the following:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.0.0-rc2-13450" />
</ItemGroup>
</Project>
Modify the "Startup.cs" file to:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
namespace OrchardCoreModularLibrary
{
public class Startup
{
public void Configure(IEndpointRouteBuilder endpoint)
{
endpoint.MapGet("/ecommerce", async context =>
{
await context.Response.WriteAsync("ModularLibrary!");
});
}
}
}
Select "Build" then "Build OrchardCoreModularLibrary".
Project built successfully.
Select the "OrchardCoreModularEmptyWebApplication" project. Modify it to the following:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OrchardCore.Application.Targets" Version="1.0.0-rc2-13450" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OrchardCoreModularLibrary\OrchardCoreModularLibrary.csproj" />
</ItemGroup>
</Project>
Click on the "Startup.cs" file. Modify it to the following:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace OrchardCoreModularEmptyWebApplication
{
public class Startup
{
// 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, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddOrchardCore();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
app.UseOrchardCore();
}
}
}
Select "Build" then "Build OrchardCoreModularEmptyWebApplication".
Build was successful.
Run the application by clicking on the green play button.
Congratulations your app is running.
Right click on "Dependencies" and then "Add Reference...".
Click on "OrchardCoreModularLibrary" to enable it and then press the "OK" button.
Run the application and go to the URL "/ModularLibrary". Congraulations, the ModularLibrary is now integrated.
Click on the "OrchardCoreModularWebAPI" project and modify it to the following:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<PackageVersion>1.0.0-rc1-10004</PackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.0.0-rc2-13450" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
</Project>
Click on "Build" then "Build OrchardCoreModularWebAPI".
Build was successful.
Select "Build" then "Build OrchardCOreModularMCVWebApplication".
Build was successful.
Run the application by clicking on the green play button.
Congratulations, your Application is running.
Select the "OrchardCoreModularMVCWebApplication" project, right click on "dependencies" and "Add Reference...".
Clink on both "OrchardCOreModularLibrary" and "OrchardCoreModularWebAPI".
Run the application by clicking the green play button.
Congradulations, your Application is running.
Now browse to "/ModularLibrary". You can see the modular library integrated.
Now browse to "/WeatherForcast". You can now see the weather data from the API.
With the Orchard Core modular framework, multiple teams can work on separate modules. The functional of an application can be added to a module. These modules can be toolkits and reused in other applications. A module can contain static assets, scripts, images, middleware, authentication, or user interface such as a dashboard.
The complete source code is located here.