> For the complete documentation index, see [llms.txt](https://docs.zongsoft.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zongsoft.com/documentation/en/framework/core/common/predication.md).

# Predicates

Composable conditional assertions from the security module event and log filtering instructions.

Predication expresses "whether the condition is true" as an object that can be executed synchronously or asynchronously. Discussions' business conditions primarily use data engine Condition; it does not have a custom PredicationBase. Therefore, the event registration of the framework security module is used here as a real use case.

## Use Delegate for Event Description

Source: [framework/Zongsoft.Security/src/Module.Events.cs](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Security/src/Module.Events.cs#L63) (excerpt; see source for context).

{% code title="Module.Events.cs" %}

```csharp
public static readonly EventDescriptor<Privileges.AuthenticatedEventArgs> Authenticated = new(Predication.Predicate<Privileges.AuthenticatedEventArgs>(OnAuthenticated), $"{nameof(Privileges.Authentication)}.{nameof(Privileges.Authentication.Authenticated)}");
public static readonly EventDescriptor<Privileges.AuthenticatingEventArgs> Authenticating = new(Predication.Predicate<Privileges.AuthenticatingEventArgs>(OnAuthenticating), $"{nameof(Privileges.Authentication)}.{nameof(Privileges.Authentication.Authenticating)}");
```

{% endcode %}

The security module uses Predication.Predicate to wrap methods into assertions corresponding to parameter types. The event descriptor and binding logic are still the responsibility of the module, and the assertion factory does not automatically complete event registration.

Source: [framework/Zongsoft.Security/src/Module.Events.cs](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Security/src/Module.Events.cs#L114) (excerpt; see source for context).

{% code title="Module.Events.cs" %}

```csharp
private static bool OnAuthenticating(Privileges.AuthenticatingEventArgs args)
{
	Current.Meter.Authentication.Authenticating.Add(1,
		new KeyValuePair<string, object>(nameof(args.Scheme), args.Scheme),
		new KeyValuePair<string, object>(nameof(args.Scenario), args.Scenario));

	return true;
}
```

{% endcode %}

This real callback first records the authentication indicator and then returns true. It shows that assertions may contain side effects; combination and short-circuiting will affect whether subsequent callbacks are executed, so assertions with side effects cannot be unconditionally rearranged as pure functions.

## Types and Combinations

| Type                          | responsibility                                    |
| ----------------------------- | ------------------------------------------------- |
| IPredication、IPredication\<T> | Non-generic and strongly typed judgment contracts |
| Predication                   | Create implementation from delegate               |
| PredicationBase\<T>           | Naming, parameter conversion and service matching |
| PredicationCollection         | Combining multiple assertions                     |
| PredicationCombination        | Short-circuit rules for AND or OR                 |

Returns success if the collection is empty; AND short-circuit on failure, OR short-circuit on success. Default object conversion affects weakly typed entries, and extensions should check parameter types, additional Parameters, and cancellation semantics.

## Actual Usage in the Log

The framework LoggerPredication makes judgments based on the log source, exception type and level. The configuration is read by Initialize. For specific implementation, see [LoggerPredication](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Core/src/Diagnostics/LoggerPredication.cs). Such rules are suitable for output filtering and should not replace business authorization.

Use [Validators](/documentation/en/framework/core/common/validator.md) when you need to return the specific failure reason; use [Data conditions](/documentation/en/framework/data/conditions-and-operands.md) when you need to let the database filter records.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zongsoft.com/documentation/en/framework/core/common/predication.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
