RePolicies 1.0.0
dotnet add package RePolicies --version 1.0.0
NuGet\Install-Package RePolicies -Version 1.0.0
<PackageReference Include="RePolicies" Version="1.0.0" />
<PackageVersion Include="RePolicies" Version="1.0.0" />
<PackageReference Include="RePolicies" />
paket add RePolicies --version 1.0.0
#r "nuget: RePolicies, 1.0.0"
#:package RePolicies@1.0.0
#addin nuget:?package=RePolicies&version=1.0.0
#tool nuget:?package=RePolicies&version=1.0.0
RePolicies
A runtime-reconfigurable policy engine built on top of ReValidator.
ReValidator validates a request DTO through IValidator<T>. RePolicies reuses that engine, but
the unit of evaluation becomes a Policy<TModel> — an envelope that carries the payload
(TModel) together with the surrounding request context: headers, cookies, the
ClaimsPrincipal, the URL and its route/query parameters.
A policy rule is therefore just IValidator<Policy<TModel>>. Because the rules are ReValidator
DynamicReconfiguration entries under the hood, they are compiled expression trees (fast) and
can be added or replaced at runtime without a redeploy.
Using ASP.NET Core? Add
RePolicies.AspNetCoreto build aPolicy<TModel>from the currentHttpContextand enforce policies via an endpoint filter or global middleware.
Install
dotnet add package RePolicies
Why Policy<TModel>?
A plain validator can only see the body. Authorization-style policies usually need more:
// "Large orders need the Manager role"
x => x.Model.Total <= 10000 || x.IsInRole("Manager")
// "Tenant header must be present"
x => x.HasHeader("X-Tenant-Id")
// "Caller must be authenticated"
x => x.IsAuthenticated
x is the Policy<TModel>. The helper methods (IsInRole, HasHeader, HasClaim, Query,
Route, Cookie, ...) are instance members on Policy<TModel>, and x.Model reaches the
payload. RePolicies registers each Policy<TModel> with ReValidator automatically, so these
helpers are callable inside expressions with no extra setup.
Helpers available inside expressions
| Member | Meaning |
|---|---|
Model |
The payload (TModel). |
IsAuthenticated |
The principal has an authenticated identity. |
IsInRole(role) |
The principal is in role. |
HasClaim(type) / HasClaim(type, value) |
The principal has the claim. |
Claim(type) |
First claim value of type, or "". |
HasHeader(name) / Header(name) |
Header presence / value ("" if absent). |
HasCookie(name) / Cookie(name) |
Cookie presence / value. |
HasQuery(name) / Query(name) |
Query-parameter presence / value. |
Route(name) |
Route value, or "". |
Method, Path, Scheme, Host, Url |
Request line / URL info. |
Getting started
using RePolicies.Abstractions;
using RePolicies.DependencyInjection;
// 1. Register ReValidator + the engine.
builder.Services.AddRePolicies(); // calls AddReValidator() for you
// 2. Configure initial policies for a model.
builder.Services
.AddPolicy<CreateOrderRequest>(new PolicyDefinition
{
Name = "OrderAmountWithinLimit",
Expression = "x => x.Model.Total <= 10000 || x.IsInRole(\"Manager\")",
DenialReason = "Orders above 10,000 require the Manager role."
})
.AddPolicy<CreateOrderRequest>(new PolicyDefinition
{
Name = "PositiveQuantity",
Expression = "x => x.Model.Quantity > 0",
DenialReason = "Quantity must be greater than zero."
});
Evaluate
public sealed class OrderService(IPolicyEngine engine)
{
public PolicyEvaluationResult Check(CreateOrderRequest request, ClaimsPrincipal user)
{
var policy = new Policy<CreateOrderRequest>(request) { User = user };
var result = engine.Evaluate(policy);
// result.IsSatisfied / result.IsDenied
// result.Failures -> { PolicyName, Reasons }
return result;
}
}
EnsureSatisfied(policy) is a throwing variant — it raises PolicyViolationException
(carrying Failures) when any policy is denied.
Reconfigure at runtime
// Add or replace a policy without a restart.
reconfigurator.Configure<CreateOrderRequest>(new PolicyDefinition
{
Name = "OrderAmountWithinLimit",
Expression = "x => x.Model.Total <= 50000 || x.IsInRole(\"Manager\")",
DenialReason = "Orders above 50,000 require the Manager role."
});
// Introspect what is currently configured.
IReadOnlyCollection<PolicyDefinition> current =
reconfigurator.GetPolicies<CreateOrderRequest>();
Need helper types in expressions?
Register them with ReValidator first, then tell AddRePolicies not to re-register it:
builder.Services.AddReValidator(o => o.RegisterType<PolicyHelpers>());
builder.Services.AddRePolicies(registerReValidator: false);
Key types
| Type | Role |
|---|---|
Policy<TModel> |
The evaluation envelope (payload + request context). |
PolicyDefinition |
A named, reconfigurable rule (Name, Expression, DenialReason, Description). |
IPolicyEngine |
Evaluate / EnsureSatisfied. |
IPolicyReconfigurator |
Add / replace / introspect policies at runtime. |
IPolicyStore |
The introspectable record of configured policies. |
IReValidatorBridge |
The single seam onto ReValidator's reconfiguration API. |
Note: ReValidator keys compiled rules by the model type's full name in process-global state, so all
Policy<TModel>evaluations for a givenTModelshare one rule set across the process (not per DI container).
License
MIT.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.9)
- ReValidator (>= 1.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RePolicies:
| Package | Downloads |
|---|---|
|
RePolicies.AspNetCore
ASP.NET Core integration for RePolicies: builds Policy<TModel> from HttpContext and enforces policies via an endpoint filter or global middleware. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 132 | 6/24/2026 |