Entity event rule
What are entity event rules ?
Entity event rules are pieces of code executed when events are triggered on the server application.
Warning
Due to identification difficulties with EF Core, entities with only an Image property set to null do not appear in modified elements.
Writing the code of an event rule
In this article, we will focus on the available events and properties.
You can either write the C# code directly in the Neos Studio code editor or in Visual Studio (after the event rule has been saved once). See more about adding / editing server code.
Example with a Saving
event rule :
/// <inheritdoc/>
public Task OnSavingAsync(ISavingRuleArguments<IOrderView> args)
{
foreach (IOrderView order in args.CreatedAndModifiedItems)
{
order.Total = order.OrderDetails.Sum((od) => od.Subtotal);
}
return Task.CompletedTask;
}
The args
parameter content is detailed in the next section.
Event rule properties
- Event rule : type of the event rule
- Business assembly : business assembly that will contain the C# class representing the event rule. The chosen assembly must belong to the event rule module or one of its children.
- Show Application layer assemblies : the source element of your code is in the
Domain
layer. This layer is the core of your business and we recommend placing all the code associated with the elements of this layer there. Placing your code in anApplication
layer assembly is only justified if your code uses elements from this layer (entity views, data objects, server methods, notifications...). See more about domain and application layers.
Available rules
Several rules are available in an entity event view. This section is an exhaustive list of these rules.
Context
The context is shared between the Saving
and Saved
events. A value added in the context during the Saving
event is available at the Saved
event level.
The context is also shared between the entity Saving
/ Saved
events and the entity view Saving
/ Saved
events. The order of triggering events is as follows:
- EntityView.Saving event
- Entity.Saving event
- Entity.Saved event
- EntityView.Saved event
Monitoring event rules execution
The execution of event rules can be tracked in the Backend monitoring
screen of the manager.