base.entity.scripting - grecosoft/NetFusion GitHub Wiki
Entity Scripting Overview
This section explains the common base types that can be implemented to execute expressions dynamically on objects at runtime. Expressions can be stored external to the application and evaluated at runtime against entities. This is useful for calculations that change overtime or must be specified at runtime.
nuget | NetFusion.Base |
---|---|
types | IAttributedEntity, IEntityScriptingService, IEntityScriptMetaRepository, ApplyScriptPredicateAttribute |
The NetFusion.Roslyn plugin, discussed in a separate section, provides an implementation based on Roslyn.
While dynamic expressions can update existing static properties, the real benefit is the ability to add new calculated properties. This can be accomplished if the entity implements the IAttributedEntity contract.
IEntityScriptingService
The IEntityScriptingService allows a script to be executed against a provided entity. This service is initialized with a collection of EntityScript instances. Each EntityScript has an ordered list of EntityExpression instances containing an expression to be applied against the entity. An EntityScript is associated with a type of entity and also named.
The implementation of the IEntityScriptingService determines if there is a named script registered for the type of entity. If a script name is not specified, the script named "default" is found. If a specific script name is specified, and there is also an associated "default" script, the service should execute the "default" script followed by the named script. This allows the "default" script to contain logic that is common across a set of scripts.
By default, the CompositeContainerBuilder registers the NullEntityScriptingSerivce as the default implementation of IEntityScriptingService. This services does not provide an implementation and acts as a pass through. This allows core plugins to utilize scripting services regardless of being configured by the host application.
IEntityScriptMetaRepository
A host application can provide an implementation of this repository to load scripts from an external data source such as SQL Server or MongoDB. After the scripts are loaded by the repository, they are used to initialize the scripting service.
ApplyScriptPredicate Attribute
This attribute can be utilize by plugins to associate a predicate with a Method or Class. For example, the NetFusion.Messaging plugin uses this attribute to determine if a specific event handler applies to a published domain-event.