Skip to content
Skills Library
Programming · Building & coding

orchardcore-rules

/orchardcore-rules

Skill for building and evaluating Orchard Core rules. Covers Condition models, IConditionEvaluator and ConditionEvaluator, IRuleService, ConditionOptions, rule registration, custom condition display drivers, condition operators, rule serialization, JavaScript condition validation, isolation and request cancellation, and Layers integration while keeping Rules distinct from Scripting. Use this skill when requests mention Orchard Core Rules, IConditionEvaluator, ConditionEvaluator, custom rule condition, rule builders, condition groups, Layers rules, or closely related Orchard Core implementation

Licence
MIT
Last repository change
21.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 21.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Skill for building and evaluating Orchard Core rules. Covers Condition models, IConditionEvaluator and ConditionEvaluator, IRuleService, ConditionOptions, rule registration, custom condition display drivers, condition operators, rule serialization, JavaScript condition validation, isolation and request cancellation, and Layers integration while keeping Rules distinct from Scripting. Use this skill when requests mention Orchard Core Rules, IConditionEvaluator, ConditionEvaluator, custom rule condition, rule builders, condition groups, Layers rules, or closely related Orchard Core implementation

Original author description

Skill for building and evaluating Orchard Core rules. Covers Condition models, IConditionEvaluator and ConditionEvaluator, IRuleService, ConditionOptions, rule registration, custom condition display drivers, condition operators, rule serialization, JavaScript condition validation, isolation and request cancellation, and Layers integration while keeping Rules distinct from Scripting. Use this skill when requests mention Orchard Core Rules, IConditionEvaluator, ConditionEvaluator, custom rule condition, rule builders, condition groups, Layers rules, or closely related Orchard Core implementation

How it works

  1. Guidelines
  2. Enable Rules
  3. Core Types
  4. Create a Custom Condition
  5. Register a Builder Condition
  6. JavaScript Conditions
  7. Use Rules with Layers
  8. Upgrading from 3.x
Original SKILL.md headings · 178 lines, 820 words
SKILL.md preview
---
name: orchardcore-rules
description: Skill for building and evaluating Orchard Core rules. Covers Condition models, IConditionEvaluator and ConditionEvaluator, IRuleService, ConditionOptions, rule registration, custom condition display drivers, condition operators, rule serialization, JavaScript condition validation, isolation and request cancellation, and Layers integration while keeping Rules distinct from Scripting. Use this skill when requests mention Orchard Core Rules, IConditionEvaluator, ConditionEvaluator, custom rule condition, rule builders, condition groups, Layers rules, or closely related Orchard Core implementation setup extension or troubleshooting work. Strong matches include work with OrchardCore.Rules, OrchardCore.Rules.Core, OrchardCore.Layers, Condition, ConditionGroup, Rule, IConditionFactory, IConditionResolver, IConditionOperatorResolver, AddRule, and AddRuleCondition. It also helps with built-in conditions, display drivers, rule evaluation, and the source-backed patterns captured in this skill.
license: Apache-2.0
metadata:
  author: CrestApps Team
  version: "1.0"
---

# Orchard Core Rules

`OrchardCore.Rules` is the structured condition system used by features such as
Layers. A rule is a model of conditions evaluated against the current request
and context. It is different from `OrchardCore.Scripting`: scripting can power
a condition, but Rules provides condition models, editors, registration,
serialization, and composable all/any groups.

## Guidelines

- Enable the exact `OrchardCore.Rules` feature; it depends on `OrchardCore.Scripting`.
- Use `Condition` as the base type for a custom condition.
- Implement `IConditionEvaluator` with `ValueTask<bool> EvaluateAsync(Condition condition)`, or derive from `ConditionEvaluator<TCondition>` to get a typed override.
- Evaluate a whole rule with `IRuleService.EvaluateAsync(rule)`. A rule, `All` group, or `Any` group with no conditions evaluates to `false`.
- Register standard conditions through `AddRuleCondition`; do not use obsolete `AddCondition`.
- Use `AddRule` when a condition has a display driver and the default condition factory is sufficient.
- Register polymorphic JSON information through the provided registration extensions.
- Keep evaluators scoped because a rule can require request-scoped services or a scripting engine.
- Use a display driver to expose a condition in the rule builder UI.
- Do not treat a JavaScript condition as a substitute for structured authorization logic.
- All C# classes in examples are sealed except View Models.

## Enable Rules

```json
{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Rules"
      ],
      "disable": []
    }
  ]
}
```

The module registers all, any, boolean, home page, URL, culture, role,
JavaScript, authenticated, anonymous, and content-type conditions. It also
registers string equality, prefix, suffix, and contains operators.

## Core Types

| Type | Purpose |
|---|---|
| `Rule` | Serializable collection of conditions evaluated as a rule. |
| `Condition` | Base model with `Name` and `ConditionId`. |
| `ConditionGroup` | Base for nested groups such as all and any. |
| `IConditionEvaluator` | Evaluates a condition instance. |
| `IConditionFactory` | Creates a model for a builder condition. |
| `IConditionResolver` | Resolves evaluators for a condition. |
| `IConditionOperatorResolver` | Resolves configured string operators. |

## Create a Custom Condition

Keep only serializable values in the condition model:

```csharp
using OrchardCore.Rules;

namespace MyModule.Rules;

public sealed class RequestHeaderCondition : Condition
{
    public string HeaderName { get; set; }
    public string ExpectedValue { get; set; }
}
```

The evaluator validates its expected condition type before using it:

```csharp
using Microsoft.AspNetCore.Http;
using OrchardCore.Rules;

namespace MyModule.Rules;

public sealed class RequestHeaderConditionEvaluator : IConditionEvaluator
{
    private readonly IHttpContextAccessor _httpContextAccessor;

    public RequestHeaderConditionEvaluator(IHttpContextAccessor httpContextAccessor)
    {
        _httpContextAccessor = httpContextAccessor;
    }

    public ValueTask<bool> EvaluateAsync(Condition condition)
    {
        if (condition is not RequestHeaderCondition headerCondition)
        {
            return ValueTask.FromResult(false);
        }

        var headers = _httpContextAccessor.HttpContext?.Request.Headers;
        var actual = headers?[headerCondition.HeaderName].ToString();

        return ValueTask.FromResult(string.Equals(
            actual,
            headerCondition.ExpectedValue,
            StringComparison.OrdinalIgnoreCase));
    }
}
```

## Register a Builder Condition

`AddRuleCondition` adds the condition to `ConditionOptions`, registers the
scoped evaluator and default singleton factory, and registers derived JSON type
metadata. Supply a third generic type argument only when a custom
`IConditionFactory` is needed:

```csharp
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Modules;
using OrchardCore.Rules;

namespace MyModule;

public sealed class Startup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddRuleCondition<
            RequestHeaderCondition,
            RequestHeaderConditionEvaluator>();
    }
}
```

When the condition needs editor UI, register its `DisplayDriver<Condition>` in
the same module. Keep view models unsealed because they bind form values.

## JavaScript Conditions

`JavascriptCondition` runs its `Script` through the scripting engine and
converts the result to a Boolean.

- The editor validates on save: a syntax error is caught as Jint
  `ScriptPreparationException` and shown as "The script couldn't be parsed",
  alongside runtime errors and non-Boolean results.
- Conditions evaluated in the same request share one engine scope, but the
  global variables are restored after each condition, so declarations in one
  condition (such as another layer's `const`) never leak into the next.
- Evaluation is bounded by `HttpContext.RequestAborted`; cancellation surfaces
  as `OperationCanceledException` and propagates like any aborted request.
  Time and statement budgets remain configurable through `IOptions<Jint.Options>`.
- Global methods come from enabled features; Layers adds `isHomepage()`,
  `isAnonymous()`, `isAuthenticated()`, `isInRole(role)`, `url(pattern)` (a
  trailing `*` is a prefix match), and `culture(name)`.

```javascript
isAuthenticated() && url("/account*")
```

## Use Rules with Layers

Layers stores a rule to decide whether a layer is active for a request. Prefer
the built-in URL, culture, role, and authentication conditions for common
targeting. Add a custom rule condition only when the selection is reusable and
needs the builder UI; simple one-off dynamic values can instead be handled by
the supported scripting condition.

Rules define no recipe step or permissions of their own. Layers stores rules in
its `Layers` recipe step and protects the editor with `ManageLayers`; a custom
consumer must define its own permission. Conditions nested in `All`/`Any`
groups are deserialized polymorphically, so recipes need their `$type` as well
as `Name` (see `orchardcore-layers`).

## Upgrading from 3.x

- JavaScript conditions no longer see globals declared by previously evaluated
  conditions in the same request.
- Saving a JavaScript condition with a syntax error now yields a validation
  message instead of an unhandled exception.
- A JavaScript condition is cancelled when the request is aborted.

Versions

The database has no other skills named orchardcore-rules.

Identical content appears in 1 other GitHub folders. We show one copy with the highest score.

Database snapshot: 13.11.2026 · package version 8faf639fdc00 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100orchardcore-layers
    Skill for configuring layers in Orchard Core. Covers layer creation, layer rules and conditions, zone-based widget visibility, the Layers and LayerSettings recipe steps, JavaScript condition methods, validation, isolation and cancellation, URL rule expressions, the ManageLayers…
  • 100orchardcore-url-rewriting
    Skill for configuring URL rewriting in Orchard Core. Covers redirect vs rewrite rules, regex pattern matching, Apache mod_rewrite flags, admin path exclusion, rule ordering with drag-and-drop in List and Grid admin list layouts, the ManageUrlRewritingRules permission, custom…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.