Overview
IntentTemplateBase is the foundational base class for all templates in Intent Architect modules. It provides essential functionality for template lifecycle management, dependency tracking, type resolution, and file output configuration.
Class Hierarchy
T4TemplateBase
└── IntentTemplateBase
└── IntentTemplateBase<TModel>
└── IntentTemplateBase<TModel, TDecorator>
IntentTemplateBase
The base class for all templates without a specific model binding.
Constructor
Unique identifier for this template. Must be unique across the application.
The output target defining where this template’s output will be written.
Properties
Unique identifier for this template instance.
Indicates whether the template should generate output. Default is true.
Indicates whether the template can be discovered by other templates. Default is true.
ExecutionContext
ISoftwareFactoryExecutionContext
Software Factory execution context providing access to application-wide services.
The output target determining where this template’s output will be written.
Metadata of the template, including file path and custom metadata.
Core Methods
RunTemplate
public virtual string RunTemplate ()
Executes the template and returns the generated output as a string.
The generated template output with normalized line endings.
GetTemplateFileConfig
public abstract ITemplateFileConfig GetTemplateFileConfig ()
Defines the file configuration including file name, location, and overwrite behavior.
Configuration for the template’s output file.
Lifecycle Hooks
Templates support several lifecycle hooks for customization:
OnCreated
public virtual void OnCreated ()
Called after the template has been created and registered.
public virtual void OnConfigured ()
Called after all templates have been configured.
AfterTemplateRegistration
public virtual void AfterTemplateRegistration ()
Executed after all templates have been registered.
BeforeTemplateExecution
public virtual void BeforeTemplateExecution ()
Executed before the template’s RunTemplate method runs.
Template Discovery
GetTemplate
public TTemplate ? GetTemplate < TTemplate >( string templateId , TemplateDiscoveryOptions ? options = null )
where TTemplate : class
Retrieves an instance of another template by its ID.
The unique template identifier or role name.
Options controlling template discovery behavior (e.g., whether to throw if not found).
The template instance if found, otherwise null.
Overloads:
// Get template bound to a specific model
GetTemplate < TTemplate >( string templateId , IMetadataModel model , TemplateDiscoveryOptions ? options = null )
// Get template bound to a model by ID
GetTemplate < TTemplate >( string templateId , string modelId , TemplateDiscoveryOptions ? options = null )
// Get template by dependency
GetTemplate < TTemplate >( ITemplateDependency dependency , TemplateDiscoveryOptions ? options = null )
TryGetTemplate
public bool TryGetTemplate < TTemplate >( string templateId , out TTemplate ? template )
where TTemplate : class
Attempts to retrieve a template instance without throwing exceptions.
true if the template was found, otherwise false.
Type Resolution
See the Type Resolution documentation for detailed information.
GetTypeName
public virtual string GetTypeName ( ITypeReference typeReference , string ? collectionFormat = null )
Resolves the type name for a given type reference.
The type reference to resolve.
Collection format to apply if the type is a collection (e.g., “List<T>”, “T[]”).
Overloads:
// Resolve from element
GetTypeName ( IElement element )
// Resolve from template
GetTypeName ( ITemplate template , TemplateDiscoveryOptions ? options = null )
// Resolve from template ID
GetTypeName ( string templateId , TemplateDiscoveryOptions ? options = null )
// Resolve from template bound to model
GetTypeName ( string templateId , IMetadataModel model , TemplateDiscoveryOptions ? options = null )
AddTypeSource
public ClassTypeSource AddTypeSource ( string templateId , string ? collectionFormat = null )
Adds a template as a source for type resolution. When resolving types, the software factory will search templates registered as type sources.
The template ID to use as a type source.
Default collection format for types resolved from this source.
The type source for fluent API configuration.
IntentTemplateBase<TModel>
Base class for templates bound to a specific model.
Constructor
Unique identifier for this template.
The output target for this template.
The model instance this template is bound to.
Properties
The model instance this template is bound to.
Methods
GetCorrelationId
public override string ? GetCorrelationId ()
Returns a correlation ID used to track template outputs between Software Factory executions. For model-based templates, this combines the template ID with the model ID.
The correlation ID in format {TemplateId}#{ModelId}, or null if the model doesn’t support correlation.
Example
public class MyEntityTemplate : IntentTemplateBase < ClassModel >
{
public const string TemplateId = "MyModule.EntityTemplate" ;
public MyEntityTemplate ( IOutputTarget outputTarget , ClassModel model )
: base ( TemplateId , outputTarget , model )
{
}
public override ITemplateFileConfig GetTemplateFileConfig ()
{
return new TemplateFileConfig (
fileName : $" { Model . Name } " ,
fileExtension : "cs"
);
}
public override string TransformText ()
{
return $@"
public class { Model . Name }
{{
{ string . Join ( Environment . NewLine , Model . Properties . Select ( p => $" public { GetTypeName ( p )} { p . Name } {{ get; set; }}" ))}
}}" ;
}
}
IntentTemplateBase<TModel, TDecorator>
Base class for templates that support both models and decorators.
Constructor
Unique identifier for this template.
The output target for this template.
The model instance this template is bound to.
Generic Type Parameters
TDecorator
ITemplateDecorator
required
The decorator contract interface. Must implement ITemplateDecorator.
Methods
GetDecorators
public IEnumerable < TDecorator > GetDecorators ()
Returns all decorators added to this template, ordered by priority.
Decorators ordered by their Priority property.
AddDecorator
public void AddDecorator ( TDecorator decorator )
Adds a decorator to this template. Called automatically by the Software Factory when a decorator is resolved.
The decorator instance to add.
GetDecoratorsOutput
protected string GetDecoratorsOutput ( Func < TDecorator , string > propertyFunc )
Aggregates output from all decorators using the specified property function.
propertyFunc
Func<TDecorator, string>
required
Function to extract string output from each decorator.
Aggregated output from all decorators.
Example
public interface IClassDecorator : ITemplateDecorator
{
string Fields ();
string Methods ();
}
public class EntityTemplate : IntentTemplateBase < ClassModel , IClassDecorator >
{
public const string TemplateId = "MyModule.EntityTemplate" ;
public EntityTemplate ( IOutputTarget outputTarget , ClassModel model )
: base ( TemplateId , outputTarget , model )
{
}
public override ITemplateFileConfig GetTemplateFileConfig ()
{
return new TemplateFileConfig (
fileName : $" { Model . Name } " ,
fileExtension : "cs"
);
}
public override string TransformText ()
{
return $@"
public class { Model . Name }
{{
{ GetDecoratorsOutput ( x => x . Fields ())}
{ GetDecoratorsOutput ( x => x . Methods ())}
}}" ;
}
}
Template Registration Learn about registering templates with the Software Factory
Output Target Configure where template outputs are written
Template Dependencies Manage dependencies between templates