Simple State Checker
The simple state checking system can be used to enable/disable an object based on some dynamic conditions. For example, you can disable a menu item on the user interface, if the current user has not granted for a given permission. The simple state checking system provides a generic way to define and check such conditions.
Definition state checker.
Any class can inherit IHasSimpleStateCheckers
to support state checks.
The MyObject
class contains a collection of state checkers, you can add your custom checkers to it.
Definition Global State Checkers
AbpSimpleStateCheckerOptions
is the options class that used to set the global state checkers for specific object.
Example: Add global state for MyObject
:
Write this inside the
ConfigureServices
method of your module.
Check the state
You can inject ISimpleStateCheckerManager<MyObject>
service to check state.
Batch check the states
If there are many instance items that require state checking, there may be performance problems.
In this case, you can implement ISimpleBatchStateChecker
. It can check multiple items at once.
You need to make sure that the same ISimpleBatchStateChecker
instance is added to the SimpleStateCheckers
of multiple instances.
SimpleBatchStateCheckerBase
inherits theISimpleBatchStateChecker
interface and implements theIsEnabledAsync
method of a single object by default.
Built-in State Checkers
The PermissionDefinition
, ApplicationMenuItem
and ToolbarItem
objects have implemented state checks and have built-in general state checkers, you can directly use their extension methods.