Core Elements

Core Elements

The Matrix Framework provides fundamental building blocks for declarative service definition and composition.

Basic Elements

ServiceNode

The root element for defining services:

<ServiceNode Name="OrderService">
    <!-- Properties -->
    <ServiceNode.Properties>
        <Property Name="Timeout" Value="30s" />
        <Property Name="MaxRetries" Value="3" />
    </ServiceNode.Properties>
    
    <!-- Resources -->
    <ServiceNode.Resources>
        <MessageTemplate Name="ErrorResponse">
            <Message Path="/error">
                <Header Name="Code" Value="{TemplateBinding Code}" />
                <Header Name="Message" Value="{TemplateBinding Message}" />
            </Message>
        </MessageTemplate>
    </ServiceNode.Resources>
</ServiceNode>

DependencyProperty

Define properties that participate in the property system:

<ServiceNode Name="OrderProcessor">
    <!-- Define dependency property -->
    <DependencyProperty Name="OrderTimeout"
                       Type="TimeSpan"
                       Default="1m"
                       Changed="OnOrderTimeoutChanged" />
                       
    <!-- Property metadata -->
    <DependencyProperty Name="MaxOrders"
                       Type="int">
        <Property.Metadata>
            <PropertyMetadata Default="100">
                <Validation>
                    <Range Min="1" Max="1000" />
                </Validation>
            </PropertyMetadata>
        </Property.Metadata>
    </DependencyProperty>
</ServiceNode>

MessageTrigger

Define triggers that respond to messages:

<ServiceNode Name="InventoryManager">
    <MessageTrigger Path="/stock/low">
        <!-- Actions when triggered -->
        <BeginStoryboard>
            <Parallel>
                <SendMessage Path="/orders/restock" />
                <SendMessage Path="/notifications/alert" />
            </Parallel>
        </BeginStoryboard>
    </MessageTrigger>
</ServiceNode>

Element Properties

Attached Properties

Properties that can be attached to any service:

<ServiceNode Name="OrderSystem">
    <!-- Set grid layout properties -->
    <Layout.Region>Processing</Layout.Region>
    <Layout.Priority>High</Layout.Priority>
    
    <ServiceNode Name="OrderProcessor">
        <!-- Inherit layout properties -->
        <Layout.SubRegion>Primary</Layout.SubRegion>
    </ServiceNode>
</ServiceNode>

Style Properties

Define reusable property sets:

<ServiceNode.Resources>
    <!-- Define service style -->
    <Style TargetType="ProcessingNode">
        <Setter Property="Timeout" Value="30s" />
        <Setter Property="RetryCount" Value="3" />
        <Setter Property="Circuit.Window" Value="1m" />
        
        <Style.Triggers>
            <MessageTrigger Path="/system/highload">
                <Setter Property="Timeout" Value="60s" />
                <Setter Property="RetryCount" Value="5" />
            </MessageTrigger>
        </Style.Triggers>
    </Style>
</ServiceNode.Resources>

Content Models

Content Property

Specify default content property:

<MessageHandler Path="/orders/create"
                ContentProperty="Steps">
    <!-- Steps is the default content -->
    <ValidateOrder />
    <ProcessOrder />
    <NotifySuccess />
</MessageHandler>

Content Template

Define how content should be processed:

<ServiceNode Name="OrderAPI">
    <ServiceNode.ContentTemplate>
        <!-- Template for processing content -->
        <DataTemplate>
            <Sequence>
                <AddMessageContext />
                <ProcessContent />
                <AddResponseHeaders />
            </Sequence>
        </DataTemplate>
    </ServiceNode.ContentTemplate>
</ServiceNode>

Markup Extensions

Resource Reference

Reference shared resources:

<ServiceNode Name="PaymentProcessor">
    <!-- Reference shared configuration -->
    <Property Name="Settings" 
             Value="{StaticResource PaymentSettings}" />
             
    <!-- Reference dynamic resource -->
    <Property Name="Timeout" 
             Value="{DynamicResource SystemTimeout}" />
</ServiceNode>

Binding Extension

Create data bindings:

<ServiceNode Name="OrderManager">
    <!-- Bind to data context -->
    <Property Name="CurrentUser" 
             Value="{Binding User.Id}" />
             
    <!-- Bind with conversion -->
    <Property Name="OrderLimit" 
             Value="{Binding Limits.Orders, 
                    Converter={StaticResource IntConverter}}" />
</ServiceNode>

Best Practices

  1. Element Design

    • Use meaningful names
    • Keep elements focused
    • Document properties
    • Follow conventions
  2. Property System

    • Use dependency properties appropriately
    • Define clear metadata
    • Handle property changes
    • Validate values
  3. Content Model

    • Choose appropriate content models
    • Use templates for consistency
    • Handle content changes
    • Document expectations