Overview
IOutputTarget represents the destination where a template’s generated output will be written. It encapsulates information about the project structure, output paths, and provides access to the Software Factory execution context.
Output targets are determined by designers with output targeting capabilities (e.g., Visual Studio, Folder Structure) and are provided to templates during instantiation.
Purpose
The output target serves several key purposes:- Location Configuration - Defines where template outputs are written
- Project Context - Provides information about the target project/application
- Role Fulfillment - Enables templates to be discovered by role
- Accessibility - Controls which templates can access other templates
Key Properties
WhileIOutputTarget is defined in the Intent.Engine assembly, templates commonly interact with it through these members:
Provides access to application-wide services including:
- Template discovery
- Metadata management
- File system operations
- Event bus
- Application configuration
Common Usage Patterns
In Template Constructors
The output target is passed to every template during construction:Accessing the Output Target
From within a template, access the output target through theOutputTarget property:
Template Registration
Output targets are provided to templates via factory functions in registrations:Output Path Configuration
GetTemplateFileConfig
Templates configure their output path throughGetTemplateFileConfig():
- The output target’s base path (configured in the designer)
- Any relative path specified in the file config
- The file name and extension
Custom Output Paths
Specify relative paths for organizing outputs:Template Accessibility
Output targets control template accessibility - which templates can discover other templates.Accessible Templates
By default, templates search for other templates accessible to the same output target:Cross-Project References
To find templates in different output targets, use template dependencies with explicit accessibility:Output Target Extensions
Common extension methods for working with output targets:Application Name
Template Output ID
Advanced Scenarios
Multiple Output Targets
Some applications have multiple output targets (e.g., different projects in a solution). Templates can interact across these boundaries:Custom Output Target Selection
In module builders, you can specify which output target a template should use:FileMetadata and Output Correlation
The output target works with file metadata to track outputs across executions:- Tracking file renames and moves
- Detecting deleted files
- Managing file merging and soft deletion
Relationship to ISoftwareFactoryExecutionContext
The output target provides access to the execution context:Best Practices
Don't Store Output Target
The output target is already stored in
IntentTemplateBase. Access it via the OutputTarget property.Use Relative Paths
Use relative paths in
GetTemplateFileConfig() to organize outputs within the output target.Consider Accessibility
Be mindful of template accessibility when searching for templates across different projects.
Leverage Extensions
Use output target extension methods for common operations like getting the application name.
Example: Multi-Project Template
This example shows a template that generates a DTO in a contracts project based on an entity in a domain project:Related Topics
IntentTemplateBase
Base classes using IOutputTarget
Template Registration
How output targets are provided to templates
Template Dependencies
Cross-output-target template dependencies