Orchard Core module that allows tenants to host their own services similar to Background tasks with hosted services in ASP.NET Core but on the tenant level.
To integrate the tenant hosted service infrastructure into Orchard Core, you can invoke the OrchardCoreBuilderExtensions.AddTenantHostedService
method. This method adds the necessary configurations and components to enable the management and execution of hosted services specific to each tenant within the Orchard Core framework.
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using VisusCore.TenantHostedService.Extensions;
var builder = WebApplication.CreateBuilder(args);
- builder.Services.AddOrchardCms();
+ builder.Services.AddOrchardCms(builder => builder.AddTenantHostedService());
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseStaticFiles();
app.UseOrchardCore();
app.Run();
The purpose of this is to identify whether a feature is enabled or disabled for a tenant. It will be enabled for every tenant through OrchardCoreBuilderExtensions.AddTenantHostedService
.
The objective of this is to designate the tenant for the hosted service manager to load the hosted services specific to that tenant.
If you're interested in observing the entire functionality in practice, take a look at the Samples project.