Authoring
As part of the rule application development process, authors may choose to make use of existing class libraries and data definitions.
Using a .NET Assembly Schema, classes may be imported as InRule Entities, along with their associated fields/properties representing InRule Fields, and methods that may be called by rules.
Like any schema type, .NET Assembly Schemas use the associated resource as the source for binding to a Rule Application’s schema. While the Schema is in place, no design-time modifications to the Rule Applications’s schema are allowed. Temporary Fields and Collections can still be added for data that does not need to be exposed outside of the rules.
Runtime
At runtime, any Rule Application that directly executes rules bound to a .NET Assembly Schema will need to have that .NET Assembly .dll (and any required dependencies) deployed along with it.
Code integrating with irSDK to execute rules will create an instance of an InRule.Runtime.Entity. This Entity will be bound to an instance of the class that was imported at design-time.
This is the default behavior for InRule schemas bound to .NET Assembly Schemas at design time.
Entities may optionally be bound to arbitrary objects whose fields/properties match the Entity Field/Collection names (duck typing), regardless of whether the schema was bound to a .NET Assembly Schema at design-time.
Design Time Schema |
Default Runtime Binding Behavior |
Optional Runtime Binding Behavior |
Unbound |
Unbound |
Arbitrary object, XElement, Dictionary<string, object>, ExpandoObject |
.NET Assembly Schema |
Bound to classes configured at design-time |
Arbitrary object, XElement, Dictionary<string, object>, ExpandoObject |
Database Schema |
Unbound |
Arbitrary object, XElement, Dictionary<string, object>, ExpandoObject |
XML Schema |
Unbound |
Arbitrary object, XElement, Dictionary<string, object>, ExpandoObject |
In addition to arbitrary objects, the following .NET Framework types are special-cased when explicitly passed to irSDK at runtime:
.NET Framework Type |
Notes |
XElement |
Child XElements will map to InRule Fields by name, and the content of each child XElement will become the Field value. |
Dictionary<string, object> |
For each item in the Dictionary, the key must match a Field name of the bound Entity. The value of each item should contain a primitive value or object value that matches the associated Field type. Even though a Dictionary implements ICollection<T>, it is not treated as an InRule Collection. |
ExpandoObject |
Behaves similarly to Dictionary where the dynamic property names should match the InRule Field names. |
Examples
Default:
var invoice = session.CreateEntity(“Invoice”);
If an object is not explicitly passed to the CreateEntity() method, an instance of the the class configured at design-time will be bound to the Entity if the source is a .NET Assembly Schema. For all other schema types, the Entity will be unbound.
Populated Configured Object:
var invoice = session.CreateEntity(“Invoice”, new Invoice() { InvoiceDate = new DateTime(2019, 1, 1) });
An instance of the class is populated and explicitly passed to the CreateEntity() method. It does not matter whether the Invoice class was imported from a .NET Assembly Schema or not. If it was not, then the object's fields/properties must match the Field names on the Entity.
Arbitrary Object:
var invoice = session.CreateEntity(“Invoice”, new LooksLikeInvoice() { InvoiceDate = new DateTime(2019, 1, 1) });
An arbitrary object that exhibits the same properties as the Invoice Enitity is explicitly passed to the CreateEntity() method.
XElement:
var invoice = session.CreateEntity(“Invoice”, XElement.Parse(“<Invoice><InvoiceDate>2019-01-01T00:00:00</InvoiceDate></Invoice>”));
XElement is created and explicitly passed to the CreateEntity() method.
Note: This should not be confused with passing XML as a string to the CreateEntity() method, as this does not bind the Entity to any object.
Dictionary<string, object>:
var invoice = session.CreateEntity(“Invoice”, new Dictionary<string, object> { { “InvoiceDate”, new DateTime(2019, 1, 1) }, {“LineItems”, new List<LineItem>()} };
Dictionary instance is initialized with the InRule Field names and associated values and explicitly passed to the CreateEntity() method.
ExpandoObject:
dynamic obj = new ExpandoObject();
bj.InvoiceDate = new DateTime(2019, 1, 1);
var invoice = session.CreateEntity(“Invoice”, obj);
ExpandoObject is populated with properties matching Field names on the Entity and explicitly passed to the CreateEntity() method.
Comments
0 comments
Please sign in to leave a comment.