Condition Context
Read runtime values and inspect the container from a condition.
component.ConditionContext gives a condition access to runtime state and the
current container.
type ConditionContext interface {
context.Context
// Container returns the container being used during condition evaluation.
Container() component.Container
}Because it embeds context.Context, conditions can read values, cancellation,
and deadlines. Container() is the Procyon-specific part: it lets a condition
check whether another component or capability is already available.
func (c ProfileCondition) Matches(ctx component.ConditionContext) bool {
return ctx.Value("profile") == c.Profile
}The context supports the same shape as a regular Go context:
| Method | Use it for |
|---|---|
Value(key) | reading runtime values |
Deadline() | checking whether evaluation has a deadline |
Done() | reacting to cancellation |
Err() | reading cancellation errors |
Container() | inspecting currently available components |
Inspect the container
Use Container() when a component should load only if another capability is
available.
type HasMetricsExporter struct{}
func (HasMetricsExporter) Matches(ctx component.ConditionContext) bool {
return component.CanResolveType[MetricsExporter](ctx.Container())
}This is useful for optional integrations. For example, a metrics reporter can load only when an exporter has already been registered and can be resolved.
Avoid hidden requirements
If a dependency is required for normal operation, prefer constructor injection. Use a condition only when the entire component is optional.
