Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContainerField ¶
ContainerField represents an injectable field in a Container struct.
Note: - Name can be "_" for override-only fields. - Type is the type to be provided (e.g. service.User, infra.Database).
func ConvertContainerFields ¶
func ConvertContainerFields(c scan.ContainerSpec) ([]ContainerField, error)
ConvertContainerFields converts a scanned ContainerSpec into resolve-ready fields.
Resolution target rules:
- If the Container has at least one `inject`-marked *public field* (non-blank), only those marked fields are included.
- Blank fields ("_") are treated as provider overrides and do NOT switch the container into explicit mode. They are included only when they are `inject`-marked.
type EmbeddedContainerRef ¶ added in v0.1.2
type EmbeddedContainerRef struct {
ContainerPkgPath string
ContainerName string
Type types.Type // *Container or Container
FuncName string // "NewInfra"
ReturnError bool
ExportedFields []ExportedField
}
EmbeddedContainerRef represents a reference to an embedded container.
func DetectEmbeddedContainers ¶ added in v0.1.2
func DetectEmbeddedContainers( fields []scan.ContainerField, registry map[string]scan.ContainerSpec, processedResults map[string]bool, ) []EmbeddedContainerRef
DetectEmbeddedContainers finds embedded container references among the container fields and returns their metadata.
registry maps "pkgPath.Name" to the corresponding ContainerSpec. processedResults maps the same key to whether the container's generated constructor returns an error.
type ExportedField ¶ added in v0.1.2
ExportedField represents an exported field of an embedded container.
type Graph ¶
type Graph struct {
Roots []*Node
}
Graph represents a resolved dependency graph.
func BuildGraph ¶
func BuildGraph(fields []ContainerField, providers []*Provider) (*Graph, error)
BuildGraph resolves dependencies starting from container fields.
type InjectTag ¶
type InjectTag struct {
// Provider selects a specific provider function by name.
// Example: `inject:"provider:service.NewUser"`
Provider string
}
InjectTag is a parsed `inject` struct tag for Container fields.
type Node ¶
Node represents a node in the resolved dependency graph.
Each node corresponds to exactly one Provider. Nodes may be shared across the graph to represent a DAG (i.e. the same Provider can be depended on by multiple parents).
type Provider ¶
type Provider struct {
PkgPath string
Name string
NameWithPkg string
ResultType types.Type
ReturnError bool
Params []types.Type
Position string
// FieldAccess, when non-empty, indicates this is a synthetic
// field-access provider. The value is the field name (e.g. "KVS").
// Instead of generating a function call, the emitter produces
// parentVar.FieldName.
FieldAccess string
// IsParam indicates this is a synthetic parameter provider.
// Instead of generating a function call, the emitter adds this
// type as a function parameter.
IsParam bool
}
Provider represents a constructor function that can produce a value for dependency injection.
A Provider is identified by its identity (pointer equality), not by value. It is treated as immutable during resolution and is shared across the dependency graph for cycle detection and override resolution.
func ConvertProviders ¶
func ConvertProviders(ps []scan.ProviderSpec) ([]*Provider, error)
ConvertProviders converts scanned ProviderDecl into resolve Provider nodes.
func CreateSyntheticProviders ¶ added in v0.1.2
func CreateSyntheticProviders(refs []EmbeddedContainerRef) []*Provider
CreateSyntheticProviders creates synthetic providers for the given embedded container references:
- A constructor provider: NewInfra() → *Infra
- Field-access providers: *Infra → infra.KVS (one per exported field)
func MergeProviders ¶ added in v0.1.2
MergeProviders merges regular and synthetic providers.
- Field-access synthetic providers override regular providers for the same result type.
- Synthetic constructor providers are skipped if a regular provider with the same NameWithPkg already exists (e.g. from a previously generated file).
func OrderProviders ¶
OrderProviders returns providers in topological order (dependencies first). Providers may appear only once even if referenced multiple times by roots.