Guides on running fire-and-forget work after a request in Orchard Core using HttpBackgroundJob.ExecuteAfterEndOfRequestAsync and ShellScope.AddDeferredTask. Covers deferred signals, post-commit callbacks, and choosing between deferred tasks, after-request jobs, and background tasks.
Ships in orchardcore. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Orchard Core provides two complementary ways to run code after the main work
of a request, without adding a scheduled IBackgroundTask. Both live in the
OrchardCore.Abstractions package, so any module can use them.
ShellScope.AddDeferredTask — runs a delegate in a fresh isolated scope
once the current shell scope tears down, after the YesSql session has been
committed. Use it to react to committed data (indexing, cache busting,
sending a signal) and to see your own just-saved changes.HttpBackgroundJob.ExecuteAfterEndOfRequestAsync — truly fire-and-forget.
It returns immediately, waits for the current HttpContext to be released
(end of the HTTP response), reloads the shell, restores the current user, and
runs the job in an isolated scope. Use it for longer work you do not want the
client to wait for.| Need | Use |
|---|---|
| Run right after commit, still part of request teardown, client waits | ShellScope.AddDeferredTask |
| Run after the response is sent, do not block the client | HttpBackgroundJob.ExecuteAfterEndOfRequestAsync |
| Only send an invalidation signal after commit | ShellScope.AddDeferredSignal |
| Run something as the scope disposes (no new scope) | ShellScope.RegisterBeforeDispose |
| Run only if the document store commit succeeded | IDocumentStore.AfterCommitSuccess<T>() |
Refresh IOptionsMonitor<T> after settings are saved | IOptionsUpdateNotifier.RequestUpdate<T>() |
| Recurring or scheduled work | IBackgroundTask (see orchardcore-background-tasks) |
The YesSql/document session commit is registered as a before-dispose callback on the shell scope. During scope teardown Orchard Core runs, in order:
RegisterBeforeDispose callbacks — this is where IDocumentStore.CommitAsync()
commits the session.AddDeferredSignal.AddDeferredTask, each in its own new scope
(with a fresh session) built from the reloaded shell.Because the commit happens in step 1 and deferred tasks run in step 3, a deferred task always observes committed data and never fights the request's open transaction. Kicking off the background job from inside a deferred task guarantees the job is only scheduled after a successful commit.
using OrchardCore.BackgroundJobs;
// Inside a controller action, driver, or handler:
await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync(
"send-welcome-email",
async scope =>
{
// 'scope' is a fresh, isolated ShellScope. Resolve services from it;
// never capture request-scoped services from the outer scope.
var emailService = scope.ServiceProvider.GetRequiredService<IEmailService>();
await emailService.SendWelcomeAsync();
});
Pass captured state through the typed overloads instead of closures over request-scoped services:
await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync(
"reindex-item",
contentItemId,
static async (scope, id) =>
{
var manager = scope.ServiceProvider.GetRequiredService<IContentManager>();
var item = await manager.GetAsync(id);
// ... process the freshly loaded, committed item
});
This is the recommended pattern when the background work must only happen if the current unit of work is actually persisted. Register a deferred task; inside it, schedule the after-request job.
using OrchardCore.BackgroundJobs;
using OrchardCore.Environment.Shell.Scope;
// e.g. inside a content handler or controller, after mutating data:
ShellScope.AddDeferredTask(async scope =>
{
// Runs in a NEW scope AFTER the session has been committed.
await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync(
"process-order",
orderId,
static async (jobScope, id) =>
{
var orders = jobScope.ServiceProvider.GetRequiredService<IOrderService>();
await orders.ProcessAsync(id);
});
});
scope.ServiceProvider; do not close over the
ambient IServiceProvider, HttpContext, or request-scoped services.ExecuteAfterEndOfRequestAsync requires an active HttpContext; if there is
no HTTP context it logs a warning and does nothing. For non-HTTP flows
(background tasks, CLI, setup) use a deferred task or run the work directly.HttpContext
to be released before running; keep controller work bounded.OrchardCore.Abstractions, referenced transitively by modules.OrchardCore:BackgroundService section (PollingTime, MinimumIdleTime, ShellWarmup; OrchardCore_BackgroundService before 4.0) does not affect them.See references/deferred-tasks-examples.md for content-handler, controller, and
signal-invalidation examples.
What SKILL.md sets; muted values are Claude Code's defaults
/orchardcore:orchardcore-deferred-tasksfrom orchardcore
npx claudepluginhub crestapps/crestapps.agentskills --plugin orchardcore140 skills in this plugin
/orchardcore-adminGuidance for the Orchard Core admin panel, including admin controllers and routes, admin menu registration with AdminNavigationProvider, ocat editor forms grouped in cards, admin pages rendering Model.Editor, the UI text casing standard, TheAdmin layout and menu colors, admin branding, the Navbar shape, the Ctrl+K quick navigation palette and QuickNavigationSource, AdminSettings such as MenuBehavior, ShowBreadcrumb, DisplayQuickNavigation, DisplayTitlesInTopbar and ActionsLayout, the AdminDashboard shape, settings pages, and admin filters and zones. Use this skill when requests mention the Orchard Core admin panel, TheAdmin, admin controllers, admin menu registration, an icon on an admin menu item, the AdminSettings recipe step, quick navigation, navigation menu behavior, the admin URL prefix, UI text casing. Strong matches include OrchardCore.Admin, AdminSettings, AdminPermissions, AdminOptions, AdminAttribute, SiteDisplayDriver, IDisplayManager./orchardcore-admin-dashboardSkill for creating admin dashboard widgets in Orchard Core. Covers the DashboardWidget stereotype, DashboardPart position and sizing, the built-in HtmlDashboardWidget, ContentsMetadata and ContentsTags widget types, custom widget content types via recipe or migration, arranging widgets in Manage Dashboard mode, widget template customization, provisioning widgets with recipes, dashboard permissions, the DashboardBreadcrumbProvider Dashboard ancestor, and the AdminDashboardContent shape used when the feature is disabled. Use this skill when requests mention Orchard Core Admin Dashboard, Create and Configure Dashboard Widgets, Enabling Admin Dashboard, Widget Configuration Properties, dashboard widget recipes, Dashboard breadcrumb, or related implementation, setup, or troubleshooting work. Strong matches include OrchardCore.AdminDashboard, DashboardPart, DashboardBreadcrumbProvider, AccessAdminDashboard, ManageAdminDashboard.Other plugins' skills for the same job