Skip to main content
The Designer API provides access to Intent Architect designers and their metadata at template execution time. Use IMetadataManager to query designers and retrieve metadata elements.

IMetadataManager

The main interface for accessing designer metadata within templates.

Accessing Designers

GetDesigner

Retrieve a specific designer instance
IDesigner GetDesigner(string applicationId, string designerId)
applicationId
string
The application ID containing the designer
designerId
string
The unique identifier of the designer
IDesigner
Designer instance containing metadata elements

Designer Extension Pattern

Intent modules typically provide extension methods on IMetadataManager to access specific designers with strongly-typed IDs.

Example: Domain Designer Access

ApiMetadataDesignerExtensions.cs
using Intent.Engine;
using Intent.Metadata.Models;

namespace Intent.Modules.ApplicationTemplate.Builder.Api
{
    public static class ApiMetadataDesignerExtensions
    {
        public const string AppTemplatesDesignerId = "22091d1e-a855-41af-ba7f-3f0b033c0fc3";

        public static IDesigner AppTemplates(
            this IMetadataManager metadataManager,
            IApplication application)
        {
            return metadataManager.AppTemplates(application.Id);
        }

        public static IDesigner AppTemplates(
            this IMetadataManager metadataManager,
            string applicationId)
        {
            return metadataManager.GetDesigner(applicationId, AppTemplatesDesignerId);
        }
    }
}

Designer Model Pattern

Designers provide access to metadata elements through strongly-typed model classes.

Example: Designer Model

DesignerModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Intent.Metadata.Models;
using Intent.Modules.Common;

namespace Intent.ModuleBuilder.Api
{
    public class DesignerModel : IMetadataModel, IHasStereotypes, IHasName, IElementWrapper
    {
        public const string SpecializationType = "Designer";
        public const string SpecializationTypeId = "7f5fcc9f-c721-4a31-bfe2-7909f4289420";

        protected readonly IElement _element;

        public DesignerModel(IElement element, string requiredType = SpecializationType)
        {
            if (!requiredType.Equals(element.SpecializationType, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new Exception(
                    $"Cannot create a '{GetType().Name}' from element with " +
                    $"specialization type '{element.SpecializationType}'. " +
                    $"Must be of type '{SpecializationType}'");
            }
            _element = element;
        }

        public string Id => _element.Id;
        public string Name => _element.Name;
        public string Comment => _element.Comment;
        public IEnumerable<IStereotype> Stereotypes => _element.Stereotypes;
        public IElement InternalElement => _element;

        public IList<DesignerReferenceModel> DesignerReferences => _element.ChildElements
            .GetElementsOfType(DesignerReferenceModel.SpecializationTypeId)
            .Select(x => new DesignerReferenceModel(x))
            .ToList();
    }

    public static class DesignerModelExtensions
    {
        public static bool IsDesignerModel(this ICanBeReferencedType type)
        {
            return type != null &&
                   type is IElement element &&
                   element.SpecializationTypeId == DesignerModel.SpecializationTypeId;
        }

        public static DesignerModel AsDesignerModel(this ICanBeReferencedType type)
        {
            return type.IsDesignerModel() ? new DesignerModel((IElement)type) : null;
        }
    }
}

Usage in Templates

Accessing Designer Metadata

public class MyTemplate : IntentTemplateBase<ClassModel>
{
    public MyTemplate(IOutputTarget outputTarget, ClassModel model)
        : base("Template.Id", outputTarget, model)
    {
    }

    public override string RunTemplate()
    {
        // Access the domain designer
        var domainDesigner = ExecutionContext.MetadataManager
            .Domain(ExecutionContext.GetApplicationConfig().Id);

        // Query elements from the designer
        var classes = domainDesigner.GetDomainModels()
            .SelectMany(x => x.Classes);

        // Generate code based on metadata
        foreach (var @class in classes)
        {
            // Process each class element
        }

        return TransformText();
    }
}

Cross-Designer Queries

// Access multiple designers
var domainDesigner = ExecutionContext.MetadataManager
    .Domain(applicationId);

var servicesDesigner = ExecutionContext.MetadataManager
    .Services(applicationId);

// Correlate elements across designers
var domainClasses = domainDesigner.GetDomainModels()
    .SelectMany(x => x.Classes);

var serviceOperations = servicesDesigner.GetServiceModels()
    .SelectMany(x => x.Operations);

// Find operations that reference domain classes
var operationsUsingDomain = serviceOperations
    .Where(op => op.Parameters
        .Any(p => domainClasses.Any(c => c.Id == p.TypeReference?.Element?.Id)));

IDesigner Interface

The IDesigner interface provides access to designer elements.
GetElementById
(string id) => IElement
Retrieve a specific element by its ID
GetElements
() => IEnumerable<IElement>
Get all root elements in the designer

Example: Querying Designer Elements

var designer = metadataManager.Domain(applicationId);

// Get all root elements
var rootElements = designer.GetElements();

// Find element by ID
var specificElement = designer.GetElementById("some-element-id");

// Query by specialization type
var classes = designer.GetElements()
    .GetElementsOfType(ClassModel.SpecializationTypeId);

Creating Designer Extension Methods

When creating a module, generate designer extension methods for easy access:
public static class MyDesignerExtensions
{
    // Designer ID constant
    public const string MyDesignerId = "12345678-1234-1234-1234-123456789abc";

    // Extension method on IMetadataManager
    public static IDesigner MyDesigner(
        this IMetadataManager metadataManager,
        IApplication application)
    {
        return metadataManager.GetDesigner(application.Id, MyDesignerId);
    }

    // Helper to get strongly-typed models
    public static IList<MyModel> GetMyModels(this IDesigner designer)
    {
        return designer.GetElements()
            .GetElementsOfType(MyModel.SpecializationTypeId)
            .Select(x => new MyModel(x))
            .ToList();
    }
}

Best Practices

Use Extension Methods

Create designer-specific extension methods on IMetadataManager with constants for designer IDs

Type-Safe Model Classes

Wrap IElement in strongly-typed model classes that validate the specialization type

Cache Designer References

Store designer references in template fields if you need to query them multiple times

Validate Elements

Check that retrieved elements exist and have the expected specialization type before using them

See Also

Build docs developers (and LLMs) love