Events Concepts
This page explains the model and generation concepts behind the event system.
Decorated model drives behavior
Properties decorated with [Property<T>] or [ReferenceProperty] are tracked by the event pipeline. Note that properties and methods are partial.
[ApiEntity]
public partial class SalesOrderDetail
{
[Required]
[Property<DataTypes.Decimal>("Quantity")]
public partial decimal Quantity { get; set; }
[ReferenceProperty("Order", DeleteAction.Cascade)]
[OppositeSideCollection("Details", "Details", CollectionLoadMode.LoadAll)]
public virtual partial SalesOrder? Order { get; set; }
}
Source generators
Generators create ...
- Event-aware partial class that implements setters and getters for your partial properties and functionality for your partial methods. This runs events and platform functionality such as enforcing required, cascade delete, etc.
- Logic containers that contain the subscribers for entities, properties, and methods.
- Logic containers that contain the subscribers for data types
Registering logic
On startup, subscribers are registered. Use attributes [Logic] on the class and [RegisterLogic] on the method. The logic container for an entity is injected. Multiple logic containers can be injected and multiple subscribers can be registered in one method.
[Logic]
public class CustomerBL(Customer.Logic customer)
{
[RegisterLogic]
public void CustomerValidation()
{
customer.Validate(c => c.Name)
.RejectIf(name => string.IsNullOrWhiteSpace(name))
.WithMessage("Customer name is required");
}
}
Multiple subscribers
Rules are additive. Multiple subscribers can coexist on the same property or entity. Prefer small, focused subscribers over large procedural handlers.